首页 > Web开发 > 详细

用jquery写的图片懒加载

时间:2017-02-13 19:00:10      阅读:178      评论:0      收藏:0      [点我收藏+]
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="jquery-1.12.3.min.js"></script>
<style type="text/css">

img{
width: 100%;height:500px;
border-bottom: 1px solid black;

}



</style>
</head>
<body>
<img class="lazy" data-src="1.jpg">
<img class="lazy" data-src="2.jpg">
<img class="lazy" data-src="3.jpg">
<img class="lazy" data-src="4.jpg">
<img class="lazy" data-src="5.jpg">
<img class="lazy" data-src="6.jpg">
<img class="lazy" data-src="7.jpg">
<img class="lazy" data-src="8.jpg">
<img class="lazy" data-src="9.jpg">
<img class="lazy" data-src="10.jpg">
<img class="lazy" data-src="11.jpg">
<img class="lazy" data-src="12.jpg">
<img class="lazy" data-src="13.jpg">
<script type="text/javascript">
lazy()
$(window).scroll(function(event){
lazy()
})
function  lazy(){
	var juli=$(window).scrollTop()+$(window).height();
	$.each($(‘.lazy‘),function(){
		var hei=$(this).offset().top+300;
		console.log(hei<juli)
		if(hei<juli){
			$(this).attr(‘src‘,$(this).data(‘src‘));
			$(this).removeClass(‘lazy‘);
		}
	})	
}

</script>
</body>
</html>

  

用jquery写的图片懒加载

原文:http://www.cnblogs.com/liuhao-web/p/6394777.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!