Jump to content

Jquery Hover() event problem!


Johns3n

Recommended Posts

Hi PHPfreaks.com

 

I'm having some trouble with Jquery's Hover() event!

 

I'm currently creating a portfolio where i need a image to shift it's position, once it's hovered,  for that purpose i've written this small script!

 

<script type="text/javascript">
$("ul.hover_block li").live("hover",
        function()
        {
	  $(this).find('img').animate
	  ({top:'50px'},{queue:false,duration:500});
        },
	function()
	{
	  $(this).find('img').animate
	  ({top:'0px'},{queue:false,duration:500});
	}
	);
</script>

 

Now the scripts works 50% because it correctly shifts the image once it's hovered, however once mouse leaves, the image doesn't shift back, it just stays in it's hovered position!

Hope you can help me! (and yes I need the live() function, because i'm running this hover() script along with a Jquery Quicksand Plugin! :)

Link to comment
Share on other sites

Solved it myself! When targeting a specific <ul> as i were, delegate() was a better option! ^^ So the solution is as it follows:

<script type="text/javascript">
$("ul.hover_block").delegate("li", 
{
  mouseenter: function() 
  { 
    $(this).find('img').animate({top:'50px'},{queue:false,duration:500});
  },
  mouseleave: function() 
  {
    $(this).find('img').animate({top:'0px'},{queue:false,duration:500});
  }
});
</script>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.