blog icon indicating copy to clipboard operation
blog copied to clipboard

懒加载(16)

Open yongheng2016 opened this issue 8 years ago • 0 comments

题目1:如何判断一个元素是否出现在窗口可视范围(浏览器的上边缘和下边缘之间,肉眼可视)。写一个函数 isVisible实现

function isVisible($node){
    var scrollTop = $(window).scrollTop(),
        viewHeight = $(window).height(),
        $nodeHeight = $node.height(), 
        $nodeOffsetTop = $node.offset().top
    if ($nodeOffsetTop<viewHeight + scrollTop && $nodeOffsetTop>scrollTop-$nodeHeight){
        return true
    }
    return false
}

题目2:当窗口滚动时,判断一个元素是不是出现在窗口可视范围。每次出现都在控制台打印 true 。用代码实现

代码: http://js.jirengu.com/nivot/1/edit?html,output

题目3:当窗口滚动时,判断一个元素是不是出现在窗口可视范围。在元素第一次出现时在控制台打印 true,以后再次出现不做任何处理。用代码实现

代码:http://js.jirengu.com/cireq/1/edit?html,output

题目4: 图片懒加载的原理是什么?

① 有图片所在位置是否出现在浏览器视口作为先决条件 ② 未进入浏览器视口的图片暂时不添加图片资源链接 ③ 当图片满足条件①的时候,给图片src属性添加资源链接

题目5: 实现视频中的图片懒加载效果

代码:http://js.jirengu.com/buxemihowo/1/edit?html,output

yongheng2016 avatar Jul 19 '17 13:07 yongheng2016