jquery unbind和off对图像不起作用

时间:2014-09-26 00:41:53

标签: jquery

当我检测到它在页面上显示时,我只尝试执行图像的幻灯片淡入。我尝试过的事情:

$(this).unbind();
$(this).unbind("scroll");
$(this).off();
$(this).off("scroll");

Here is the jsfiddle

1 个答案:

答案 0 :(得分:1)

错误的部分是您使用$(this)而非使用$(window),在您的小提琴中$(this)将引用.fade-in div ..

$(document).ready(function() {
    $(window).scroll(function() {
        $('.fade-in').each(function(i) {
            var bottom_of_object = $(this).offset().top + $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();
            /* If the object is completely visible in the window, fade it it */
            if (bottom_of_window > bottom_of_object - $(this).outerHeight() / 2) {
                $(this).animate({
                    opacity : 1,
                    marginLeft : '+=200px'
                }, 500);
            }
            $(window).off("scroll");
        });
    });
});

查看此Fiddle ..

已编辑多个div的小提琴:Here

相关问题