首页 > 移动平台 > 详细

预加载动画,移动端常用的加载前的百分比动画

时间:2017-07-06 12:58:56      阅读:295      评论:0      收藏:0      [点我收藏+]
<script>
            function loading() {

                function Load() {}

                Load.prototype.loadImgs = function(urls, callback) {
                    this.urls = urls;
                    this.imgNumbers = urls.length;
                    this.loadImgNumbers = 0;
                    var that = this;
                    for(var i = 0; i < urls.length; i++) {
                        var obj = new Image();
                        obj.src = urls[i];
                        obj.onload = function() {
                            that.loadImgNumbers++;
                            callback(parseInt((that.loadImgNumbers / that.imgNumbers) * 100));
                        }
                    }
                };

                var loader = new Load();

                loader.loadImgs([
                    // 将所有需要加载的图片地址写于此处
                    "img/about1.jpg",
                    "img/about2.jpg",
                ], function(percent) {
                    // 假设显示百分比的元素为 $(".percent")
                    $(".percent").text(percent + ‘%‘);

                    // 加载结束后,隐藏相应的 loading 或遮罩 
                    if(percent == 100) {
                        $(".mask").css(‘display‘, ‘none‘);
                    }
                });
            }
            // 执行 loading 方法
            loading();
        </script>

 

预加载动画,移动端常用的加载前的百分比动画

原文:http://www.cnblogs.com/moxiaowohuwei/p/7125619.html

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