Johns3n Posted July 22, 2011 Share Posted July 22, 2011 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 https://forums.phpfreaks.com/topic/242612-jquery-hover-event-problem/ Share on other sites More sharing options...
Johns3n Posted July 22, 2011 Author Share Posted July 22, 2011 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 https://forums.phpfreaks.com/topic/242612-jquery-hover-event-problem/#findComment-1246055 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.