Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

jQuery Navigation Slider

Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
I got pretty interested in JavaScripting so tried a lot of cool stuff and I love it very much :D

Need some help with my horizontal navigation I tried, basically the subnav slide down when you hover on the 'Point on me', and it slides up when your mouse goes out from the text.

But I couldn't make it, like..erm..when you hover the subnav and the 'Point on me', it will stop there until your mouse got out off the 'Point on me' and subnav.

But the problem is, I can't code both of them coding getting the same argument cause they aren't in the same div, they are separated far away.

DEMO:


Source codes:
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Toggle me </title>

<style type="text/css">
div {
	float:left;
	padding-left:10px;
}

.nav {
	background:url(subnav.png) no-repeat;
	width:844px;
	height:22px;
	display:none;
}
</style>

</head>
<body>
<div class="toggle" style="cursor:pointer"><b>Point on me</b></div>

<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<br />

<!-- NAV POP OUT -->
<div class="nav"></div>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
	$('.toggle').hover(function(){
		$('.nav').slideDown();
	},
	function (){
		$('.nav').slideUp();
	});
			
});
</script>
</body>
</html>

Hope you guys understand my bad english :(
Please give me a hand..please :*:
 
Joined
Jul 26, 2006
Messages
3,634
Reaction score
1,007
EDIT:
Demo -

I've not tested it but this should work:
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Toggle me </title>

<style type="text/css">
div {
	float:left;
	padding-left:10px;
}

.nav {
	background:url(subnav.png) no-repeat;
	width:844px;
	height:22px;
	display:none;
}
</style>

</head>
<body>
<div class="toggle" style="cursor:pointer"><b>Point on me</b></div>

<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<br />

<!-- NAV POP OUT -->
<div class="nav"></div>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
	$('.toggle').hover(
		function(){
			$('.nav').slideDown();
		},
		function (){
			menuTimer = setTimeout("$('.nav').slideUp();", 2000);
		}
	);
	$('.nav').hover(
		function() {
			clearTimeout(menuTimer);
		},
		function() {
			$(this).slideUp();
		}
	);		
});
</script>
</body>
</html>

It will only go up if you take your mouse off of the subnav. If you take your mouse off of .toggle and don't put it on the subnav within 2 seconds, it will auto close to prevent it from being open constantly.
 
Last edited:
Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
EDIT:
Demo -

I've not tested it but this should work:
Code:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Toggle me </title>

<style type="text/css">
div {
	float:left;
	padding-left:10px;
}

.nav {
	background:url(subnav.png) no-repeat;
	width:844px;
	height:22px;
	display:none;
}
</style>

</head>
<body>
<div class="toggle" style="cursor:pointer"><b>Point on me</b></div>

<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<div>RANDOM</div>
<br />

<!-- NAV POP OUT -->
<div class="nav"></div>

<script src="js/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
	$('.toggle').hover(
		function(){
			$('.nav').slideDown();
		},
		function (){
			menuTimer = setTimeout("$('.nav').slideUp();", 2000);
		}
	);
	$('.nav').hover(
		function() {
			clearTimeout(menuTimer);
		},
		function() {
			$(this).slideUp();
		}
	);		
});
</script>
</body>
</html>

It will only go up if you take your mouse off of the subnav. If you take your mouse off of .toggle and don't put it on the subnav within 2 seconds, it will auto close to prevent it from being open constantly.
Code:
$(document).ready(function() {
    $('.toggle').hover(

    function() {
        $('.nav').slideDown();
    }, function() {
        menuTimer = setTimeout("$('.nav').slideUp();", 200);
    });
    $('.nav').hover(

    function() {
        clearTimeout(menuTimer);
    }, function() {
        $('.nav').slideUp();
    });
});
Hell yea :) it works :D thanks bro~

btw, is it possible to use if and else statement eg, a=1 blah blah
ps: I replaced 2000 to 200
 
Last edited:
Joined
Jul 26, 2006
Messages
3,634
Reaction score
1,007
Code:
$(document).ready(function() {
    $('.toggle').hover(

    function() {
        $('.nav').slideDown();
    }, function() {
        menuTimer = setTimeout("$('.nav').slideUp();", 200);
    });
    $('.nav').hover(

    function() {
        clearTimeout(menuTimer);
    }, function() {
        $('.nav').slideUp();
    });
});
Hell yea :) it works :D thanks bro~

btw, is it possible to use if and else statement eg, a=1 blah blah
ps: I replaced 2000 to 200

Of course!
JS has if/else, for, while, etc.

2
 
Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
Of course!
JS has if/else, for, while, etc.

2

And shitzzie this doesn't work o.o
I wonder did any statement are wrongly coded?
Code:
//Toggle Sub Navigation
$(document).ready(function(){
	$('.toggle').hover(
		function(){
			$('.dropdown').slideDown();
            a=1;
		},
		function (){
			if(a==1) {
            	$('.dropdown').slideUp();
            }
		}
	);
	$('.dropdown').hover(
		function() {
			a=2;
		},
		function() {
			$(this).slideUp();
		}
	);		
});
 
Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
That should work. What are you trying to accomplish here, though?
nah it didn't

so I tried this and it work :)
Code:
//Toggle Sub Navigation
$(document).ready(function(){
	$('.toggle').hover(
		function(){
			$('.dropdown').slideDown();
		},
		function(){
			a=1;
		});
		
	$('.dropdown').mouseout(
		function() {
			a=1;
		}
	);		
	$('body').hover(function(){
			if(a==1) {
				$('.dropdown').slideUp();
			}
		});
});
But I found it funny when I use this, what can I replace it with?
Code:
	$('body').hover(function(){

pss: top secret XD
 
Joined
Nov 17, 2008
Messages
800
Reaction score
1,392
Jquery is a framework of Javascript. Before you use Jquery, you should master the fundamentals of Javascript because those same fundamentals carry over to Jquery. Making functions, If/Else statements, etc. These fundamentals exist in most programming languages, and if you're planning on a career with programming, you will deal with them for your entire life.
 
Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
Jquery is a framework of Javascript. Before you use Jquery, you should master the fundamentals of Javascript because those same fundamentals carry over to Jquery. Making functions, If/Else statements, etc. These fundamentals exist in most programming languages, and if you're planning on a career with programming, you will deal with them for your entire life.
this is going to be hard o.o gonna learn a new programming language...
I wonder where should I start with?
 
Joined
Dec 15, 2009
Messages
1,387
Reaction score
236
maybe I was stupid lol duck!

Code:
//Toggle Sub Navigation
$(document).ready(function(){					   
	$('.toggle').hover(function(){
		$('.dropdown').slideDown()
	},
	function(){
		$('.dropdown').slideUp();
	});
	
	$('.dropdown').hover(function(){
		$('.dropdown').stop(); //solved all my problem instead of timeout and if/else
	},
	function(){
		$(this).slideUp();
	});
});

LOL duck TOOK ME TWO DAYS!!
 
Back
Top