NameSilo

Jquery and jquery ui - Help needed!

Spaceship Spaceship
Watch

PoorDoggie

Soon to be RICHdoggie!VIP Member
Impact
18
Ok, so I've got this tabbed display on my website at the moment:

Future Ventures - Local Marketing

As you can see, the content of the blue area changes as you mouseover the nav buttons, and the colour of the nav buttons change (two different images).

The problem now is that I cannot find any way to do these things:
  1. I want the content of the boxes to stay the same ONLY when the mouse is over the corresponding tab OR the content below... otherwise I want it to revert back to the "home" option.
  2. I want the tab that you have mouseover's image to stay changed when you move to the content below, and only to change back to normal when the mouse is over a different tab option OR when the mouse isn't over any of it.

I'm sorry to be thick and stuff, but I've looked everywhere, typed all possible combinations of search terms into google, picked through the jquery website (which is incredibly difficult to understand, I think) and I can't figure it out... heres my code:

HTML:
<? $page="home"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Future Ventures - Local Marketing</title>
<link rel="stylesheet" type="text/css" href="default.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready( function()
{
ROLL.rollover.init();
}
);

ROLL = {};

ROLL.rollover =
{
   init: function()
   {
      this.preload();

      $(".ro").hover(
         function () { $(this).attr( 'src', ROLL.rollover.newimage($(this).attr('src')) ); },
         function () { $(this).attr( 'src', ROLL.rollover.oldimage($(this).attr('src')) ); }
      );
   },

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', ROLL.rollover.newimage( $(this).attr('src') ) ); });
      });
   },

   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_on' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_on\./, '.');
   }
};
$(function() {
	$("#tabs").tabs({
		event: 'mouseover'
	});
});
</script>
</head>

<body>
<center>
<table cellpadding="0" cellspacing="0" width="1000px">
	<tr>
		<td><img src="images/header.gif" alt="Future Ventures | Raise revenue, increase repeat custom and maximise profits" /></td>
	</tr>
	<tr>
		<td id="nav">
		<?php

		// navigation menu... grr...
		// start nav array:
		$navButton = array(
						'home'		=>	'images/home.gif',
						'about'		=>	'images/about.gif',
						'packages'	=>	'images/packages.gif',
						'portfolio'	=>	'images/portfolio.gif',
						'contact'	=>	'images/contact.gif');

		$navLinks = array(
						'home'		=>	'index.php',
						'about'		=>	'about.php',
						'packages'	=>	'packages.php',
						'portfolio'	=>	'portfolio.php',
						'contact'	=>	'contact.php');

		// page should be defined at the top of each script...
		if($page == "home"){
			$navButton['home'] = "images/home_on.gif";
		}
		else if($page == "about"){
			$navButton['about'] = "images/about_on.gif";
		}
		else if($page == "packages"){
			$navButton['packages'] = "images/packages_on.gif";
		}
		else if($page == "portfolio"){
			$navButton['portfolio'] = "images/portfolio_on.gif";
		}
		else if($page == "contact"){
			$navButton['contact'] = "images/contact_on.gif";
		}
		else{
			// correct the page
			$page = "home";
			// set home button
			$navButton['home'] = "images/home_on.gif";
		}

		// ok... lets start building the navbar...
		echo     '<div id="tabs"><ul>
                      <li><a href="#tabs-1"><img src="'.$navButton['home'].'" class="ro" /></a></li>
                      <li><a href="#tabs-2"><img src="'.$navButton['about'].'" class="ro" /></a></li>
                      <li><a href="#tabs-3"><img src="'.$navButton['packages'].'" class="ro" /></a></li>
                      <li><a href="#tabs-4"><img src="'.$navButton['portfolio'].'" class="ro" /></a></li>
                      <li><a href="#tabs-5"><img src="'.$navButton['contact'].'" class="ro" /></a></li>
                  </ul>';

			// figures theres an easy way to do this...
			echo             '<div id="tabs-1"><img src="images/'.$page.'_box.gif" /></div>
                              <div id="tabs-2"><img src="images/about_box.gif" /></div>
                              <div id="tabs-3"><img src="images/packages_box.gif" /></div>
                              <div id="tabs-4"><img src="images/portfolio_box.gif" /></div>
                              <div id="tabs-5"><img src="images/contact_box.gif" /></div>
                       </div>';

			?>
		</td>
	</tr>
	<tr>
		<td><img src="images/spacer.gif" width="1000px" height="12px" /></td>
	</tr>
	<tr>
		<td class="content">
   </tr>
</table>
</body>
</html>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
you could try using image maps in conjunction with what you have so that it reverts back when they leave the specified area. read: JavaScript Image Maps


im also very impressed with your desire to learn/try new things. i suggested trying this method only a few hours ago and you already have done so much. well done.
 
0
•••
I love learning new stuff. I find it difficult sometimes to know what to learn in order to do something. Its always helpful, interesting and useful to be pointed in the right direction.

Also, I like the way you give help. Since you mentioned jquery and ajax to me I've learnt so much about it. (its complicated, and I can see how much easier it is with jquery, but its still complicated)... whereas giving a fix wouldn't help me learn anything.

*goes to look up image maps now*

Thanks :)
 
0
•••
Ok... i looked up image maps, but I don't really understand how you thought that it would work with my issue, so I decided to have another go with jquery (forget jquery ui)...

I managed to get a rough idea going and make it work with the code changing the background colour of a div when you mouseover different elements...
HTML:
<html>

<head>
<title>Test</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(
	function(){
		$('#outer').hover(
			function(){ return; },
			function(){ $('#box').css({background: 'white'}); }
		);
		$('#outer .spacer').hover(
			function(){ $('#box').css({background: 'white'}); },
			function(){ return; }
		);
		$('#outer ul li').hover(
			function(){ $('#box').css({background: $(this).attr('id')}); },
			function(){ $('#box').css({background: $(this).attr('id')}); }
		);
	}
);
</script>

<style>

#outer{

	width: 320px;
	height: 500px;
	margin: 0;
	padding: 0;

}

#outer ul{
	
	margin: 0;
	padding: 0;

}

#outer ul li{

	list-style: none;
	display: inline;
	margin: 0;
	padding: 0;

}

#box{

	border: 1px black solid;
	margin: 0;
	padding: 0;
	width: 320px;
	height: 450px;

}

#container{
	
	width: 320px;

}



</style>

</head>

<body>

<div id="outer">
	<div id="container"><ul>
		<li id="white" style="background: white;"><img src="images/spacer.gif" width="88" height="30" /></li>
		<li id="red" style="background:red"><img src="images/spacer.gif" width="30" height="30" /></li>
		<li id="blue" style="background:blue"><img src="images/spacer.gif" width="30" height="30" /></li>
		<li id="black" style="background:black"><img src="images/spacer.gif" width="30" height="30" /></li>
		<li id="green" style="background:green"><img src="images/spacer.gif" width="30" height="30" /></li>
		<li id="white" style="background: white;"><img src="images/spacer.gif" width="88" height="30" /></li>
	</ul></div>
	<div id="box">Mouseover a color... Color changes in here</div>
</div>


</body>

</html>
(see it work at Test)

Anyway, so working from that I tried to make it work in my website... but its not working. :(

So, javascript:
Code:
$(document).ready( function()
{
	function(){
		$('#outer').hover(
			function(){ return; },
			function(){ $('#outer div').css({display: 'none'}); $('#outer #<? echo $page; ?>_box').css({display: 'block'}]); }
		);
		$('#outer ul li').hover(
			function(){ $('#outer div').css({display: 'none'}); $('#outer #'+$(this).attr('id')+'_box').css({display: 'block'}); },
			function(){ return; }
		);	
	};
	ROLL.rollover.init();
}
);
(the ROLL.rollover.init(); function is defined later... its the other stuff thats not working, although if it helps, the ROLL.rollover.init(); function isn't working when the script is written as such, it worked before though, so I know theres no problem with the function, for some reason that bit of code there isn't working, and I can't see why.)

I don't know if you can help me at all? Its probably a stupid mistake somewhere. :( :-/
 
Last edited:
0
•••
i was figuring that you could use the imagemaps to add a "hitbox" type element which would keep/remove the page when you hovered on/off it. i've personally never worked with hitboxes, so it may be more difficult than i think it is.

im not sure why it wouldn't translate to your site... only thing i can see (syntax-ically) is that there seems to be an extra close square bracket (i.e. ]) at then end of "function(){ $('#outer div').css({display: 'none'}); $('#outer #<? echo $page; ?>_box').css({display: 'block'}]); }"
 
0
•••
lmao... thanks for your help... that was one of many problems.

I took that out, but it still wouldn't work, so I had a really close look. I had two functions like this:

HTML:
function(){ function(){} }

then it wouldn't work because I appended one function with a ; whoops.

pfft... anyway, its working =D Now, i've just gotta clear up the messy coding for the images change thing. :) I'll let you know if i run into any more problems, or if it ever works! :D hehe

thank you very much.

---------- Post added at 02:35 AM ---------- Previous post was at 01:46 AM ----------

OMG OMG OMG OMG OMG!!!

I've done it! :p hehehe

Thank you very much for your help... its greatly appreciated! :)
 
0
•••
hey, job well done - glad you finally got it!
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back