jquery 懒加载&回到顶部

2016-09-02  本文已影响37人  coolheadedY
function isVisible($node){
        if ($(window).scrollTop() >= ($node.offset().top - $(window).height()) && 
            $(window).scrollTop() <= ($node.offset().top + $node.height())) {
            console.log('在可视窗口中');
            return;
        } 
    }
$(window).on('scroll', function(){
        isVisible($node);
    });
    function isVisible($node){
        if ($(window).scrollTop() >= ($node.offset().top - $(window).height()) && 
            $(window).scrollTop() <= ($node.offset().top + $node.height())) {
            console.log('true');
            return;
        } 
    }
$(window).on('scroll', function(){
        if (!$box.data('data-show')) {
            isVisible($node);
        }
    });
    function isVisible($node){
        if ($(window).scrollTop() >= ($node.offset().top - $(window).height()) && 
            $(window).scrollTop() <= ($node.offset().top + $node.height())) {
            console.log('true');
            $node.data('data-show', true);
            return;
        } 
    }
<img src="" data-src="url" alt="">

本博客版权归 本人和饥人谷所有,转载需说明来源

上一篇 下一篇

猜你喜欢

热点阅读