开发者

Jquery stops when content is updated via Ajax

I have:

$('.image.txt_over').hover(function(){
    $(".screen"开发者_Python百科, this).stop().animate({top:'165px'},{queue:false,duration:300});
    $(this).fadeTo("slow", 1);

}, function() {
    $(".screen", this).stop().animate({top:'226px'},{queue:false,duration:460});
});     

and I am trying to keep the jquery hover effect once a new set of images are refreshed via Ajax. Currently the jquery is killed once the Ajax refreshes.

I think I need .delegate() or .live() but cant seem to get either to work. Still learning jquery.


Try this:

$('body').delegate('.image.txt_over', 'mouseover mouseout', function(event) {
    if (event.type == 'mouseover') {
        $(".screen", this).stop().animate({top:'165px'},{queue:false,duration:300});
        $(this).fadeTo("slow", 1);
    } else {
        $(".screen", this).stop().animate({top:'226px'},{queue:false,duration:460});
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜