Jquery Delay

Hi Experts,

I have this script:
$("#top-bar .image-link").mouseover(
  function () {
    $('#sub-menu-container').stop().animate({
      top: '50'}, 500,function() {});
  });


But i'd like to wait to someone has hovered for 2 seconds before it triggers the effect...

Any ideas?

Many Thanks
maccaj51Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StingRaYCommented:
Try this:

var timer = 0;
$("#top-bar .image-link").hover(function(){
    timer = setTimeout("animate_me()", 2000); // start timer when mouse is moved in
}, function() {
    clearTimeout(timer); // stop it if mouse is moved out
});
function animate_me() {
    $('#sub-menu-container').stop().animate({
      top: '50'}, 500,function() {}); 
  });
}

Open in new window

0
maccaj51Author Commented:
Thanks Sting Ray but That seems to have come up with an error?
0
StingRaYCommented:
Sorry. Try this:

var timer = 0;
$("#top-bar .image-link").hover(function(){
    timer = setTimeout("animate_me()", 2000); // start timer when mouse is moved in
}, function() {
    clearTimeout(timer); // stop it if mouse is moved out
});
function animate_me() {
    $('#sub-menu-container').stop().animate({
      top: '50'}, 500,function() {}); 
}

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

maccaj51Author Commented:
Hi Stingray...
Still doesnt seem to be working? The code no longer has an error but it doesnt complete the function the old code did, regardless of how long i hover
0
StingRaYCommented:
Try this:

var timer = 0;
$(function(){
	$("#top-bar .image-link").hover(function(){
		timer = setTimeout("animate_me()", 2000); // start timer when mouse is moved in
	}, function() {
		clearTimeout(timer); // stop it if mouse is moved out
	});
});
function animate_me() {
    $('#sub-menu-container').stop().animate({top: '50'}, 500); 
}

Open in new window


I have move event-binding code into $() function to make sure the code will be run when all elements are ready.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
maccaj51Author Commented:
Its still no working im afraid sting ray!
0
StingRaYCommented:
Check this out:

http://jsfiddle.net/kZeb3/

It is working.
0
maccaj51Author Commented:
You're right it is... It was me being a mug! many thanks!!!
0
maccaj51Author Commented:
Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.