开发者

Jquery stops when content is updated via Ajax

开发者 https://www.devze.com 2023-02-28 12:20 出处:网络
I have: $(\'.image.txt_over\').hover(function(){ $(\".screen\"开发者_Python百科, this).stop().animate({top:\'165px\'},{queue:false,duration:300});

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

精彩评论

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