jquery预加载显示百分比
<img class="bj loadimg" loadimg="/weiqingshu/images/1/bj.jpg"/>
<script type=”text/javascript” src=”/caigeci/js/jquery.imgpreload.min.js”></script>
imgNum=0;
var load_img = [];
/*$('.loadimg').each(function () {
var loadimg=$(this).attr('loadimg');
load_img.push(loadimg);
})*/
load_img.push( '/caigeci/images/answer0.jpg' );
load_img.push( '/caigeci/images/answer1.jpg' );
/*ss*/
jQuery.imgpreload(load_img, {
each: function () {
/*this will be called after each image loaded*/
var status = $(this).data('loaded') ? 'success' : 'error';
if (status == "success") {
var v = (parseFloat(++imgNum) / load_img.length).toFixed(2);
console.log(Math.round(v * 100) + "<sup>%</sup>");
}
},
all: function() {
console.log('全部加载完成');
/*$('.loadimg').each(function () {
var loadimg=$(this).attr('loadimg');
$(this).attr('src',loadimg);
})*/
}
});
ps:加载的文件个数 /全部文件个数 的百分比就是进度
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/18829.html