首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >操作inview.js触发的时间

操作inview.js触发的时间
EN

Stack Overflow用户
提问于 2013-02-23 20:09:39
回答 1查看 839关注 0票数 2

我想知道我如何操作inview.js脚本,当它被触发的时刻不是在视口中的第一个像素,而是最后一个元素在输出的时候,而是例如50像素以后或更早。inview.js的脚本是

代码语言:javascript
复制
(function ($) {
function getViewportHeight() {
    var height = window.innerHeight; // Safari, Opera
    var mode = document.compatMode;

    if ( (mode || !$.support.boxModel) ) { // IE, Gecko
        height = (mode == 'CSS1Compat') ?
        document.documentElement.clientHeight : // Standards
        document.body.clientHeight; // Quirks
    }

    return height;
}

$(window).scroll(function () {
    var vpH = getViewportHeight(),
        scrolltop = (document.documentElement.scrollTop ?
            document.documentElement.scrollTop :
            document.body.scrollTop),
        elems = [];

    // naughty, but this is how it knows which elements to check for
    $.each($.cache, function () {
        if (this.events && this.events.inview) {
            elems.push(this.handle.elem);
        }
    });

    if (elems.length) {
        $(elems).each(function () {
            var $el = $(this),
                top = $el.offset().top,
                height = $el.height(),
                inview = $el.data('inview') || false;

            if (scrolltop > (top + height) || scrolltop + vpH < top) {
                if (inview) {
                    $el.data('inview', false);
                    $el.trigger('inview', [ false ]);                        
                }
            } else if (scrolltop < (top + height)) {
                if (!inview) {
                    $el.data('inview', true);
                    $el.trigger('inview', [ true ]);
                }
            }
        });
    }
});

// kick the event to pick up any elements already in view.
// note however, this only works if the plugin is included after the elements are bound to 'inview'
$(function () {
    $(window).scroll();
});
})(jQuery);

所有学分都归here所有

我的尝试是添加一个值来偏移顶部的top = $el.offset().top + 50,,这是可行的!但是如何更改自下而上的值呢?谢谢,泰德

EN

回答 1

Stack Overflow用户

发布于 2013-10-11 04:11:23

我推荐使用http://imakewebthings.com/jquery-waypoints/

你可以这样调用,从底部起10%就能达到你想要的效果:

代码语言:javascript
复制
    $('.flyIn').waypoint(function() {
    $(this).removeClass('hidden');
    $(this).addClass('animated fadeInUp');
    }, { offset: '90%' });
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15040386

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档