zoukankan      html  css  js  c++  java
  • 用jquery写的图片懒加载

    <%@ 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{
     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>
    

      

  • 相关阅读:
    .net2.0中使用SqlBulkCopy进行大批量数据迁移
    css 的不兼容性问题
    使用负边距创建自适应宽度的流体布局
    关于元素的 width属性无效果
    jQuery UI
    ajax.dll 与 ajaxpro.dll
    汉字转拼音
    基础数据库对象类
    各种弹出窗口函数
    Email工具类
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/6394777.html
Copyright © 2011-2022 走看看