zoukankan      html  css  js  c++  java
  • Jquery ajax 与 lazyload的混合使用(实现图片异步加载)

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="utf-8" />
            <title>This is a ajax test</title>
            <script type="text/javascript" src="js/jquery-3.1.1.js"></script>
            <script type="text/javascript" src="js/test_js.js"></script>
            <script type="text/javascript" src="js/jquery.lazyload.js"></script>
            <script type="text/javascript">
                $(function() {
                    url = $.ajax({
                        type: "get",
                        url: "img_url.txt",
                        async: true,
                        success: function() {
                            $("img.lazy").attr("data-original", url.responseText);
                            $("img.lazy").lazyload({
                                effect: "fadeIn",
                            });
                        }
                    });
                });
            </script>
            <link rel="stylesheet" href="css/img.css" />
        </head>
    
        <body>
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
            <img class="lazy" src="img/bmw_m1_hood.jpg" width="100px" height="100px">
        </body>
    
    </html>
    
    
    
    CSS:
    .lazy{
        margin-top: 1000px;
    }

    思路是先用ajax请求图片地址,然后在success里面用Lazyload实现加载图片,这种方式效率高,用户亲和力好

  • 相关阅读:
    struts2 spring3 整合
    SilverLight 银光 基础.net 跨网页,桌面软件体验更好,但是要这个插件
    struts 理解 action
    vb 坐标点击
    错误struts2 json There is no Action mapped for namespace
    struts 与 jquery 整合
    springmvc jquery 界面没回应
    css 相关学习
    spring + ehcache 配置
    jquery json 结合
  • 原文地址:https://www.cnblogs.com/yzjT-mac/p/6371468.html
Copyright © 2011-2022 走看看