图片按顺序加载

    <div>1. <img src="" alt="" _src='https://t7.baidu.com/it/u=2621658848,3952322712&fm=193&f=GIF'></div>
    <div>2. <img src="" alt="" _src='https://t7.baidu.com/it/u=1415984692,3889465312&fm=193&f=GIF'></div>
    <div>3. <img src="" alt="" _src='https://t7.baidu.com/it/u=334080491,3307726294&fm=193&f=GIF'></div>
    <div>4. <img src="" alt="" _src='https://t7.baidu.com/it/u=774679999,2679830962&fm=193&f=GIF'></div>
    <div>5. <img src="" alt="" _src='https://t7.baidu.com/it/u=3683704156,288749744&fm=193&f=GIF'></div>
    <script>
        var images = document.images
        function loadImg(images,index) {
            index = index || 0
            if(images&&images.length>index){
                var img = new Image()
                img.src =  images[index].getAttribute('_src')
                img.onload = function(){
                    images[index].src = this.src
                    loadImg(images,++index)
                }
            }
        }
        loadImg(images,0)
   </script>
posted @ 2022-10-21 17:25  亦茫茫  阅读(32)  评论(0编辑  收藏  举报