2021-03-05 16:07发布
通过Zepto库释放图片资源的方法。代码如下:
$.fn.remove = function(){
return this.each(function(){
if(this[removed]){
if(this.tagName === 'IMG'){
cache.push(this)
this.src = '[removed]R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='//让图片资源指向一个空白的gif图片。用cache变量保存dom的引用,60秒。让垃圾回收器有时间回收多余的图片资源。
if (timeout) clearTimeout(timeout)
timeout = setTimeout(function(){ cache = [] }, 60000)
}
this[removed].removeChild(this)
})
最多设置5个标签!
通过Zepto库释放图片资源的方法。代码如下:
$.fn.remove = function(){
return this.each(function(){
if(this[removed]){
if(this.tagName === 'IMG'){
cache.push(this)
this.src = '[removed]R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs='//让图片资源指向一个空白的gif图片。用cache变量保存dom的引用,60秒。让垃圾回收器有时间回收多余的图片资源。
if (timeout) clearTimeout(timeout)
timeout = setTimeout(function(){ cache = [] }, 60000)
}
this[removed].removeChild(this)
}
})
}
一周热门 更多>