【发布时间】:2017-02-02 22:42:43
【问题描述】:
我有一个为 Tumblr 设计的脚本,它会修改内联图像(在文本/标题/等帖子中,而不是照片/照片集帖子中)中的部分 img src 以显示更大,作为加载到的默认 url Tumblr 强制它们为 500 像素或更小,并且许多图像通常更大并且可以拉伸以填充它们的容器。但是,有时较大图像的 url 并不总是可用的,我想知道如果更改 url 会破坏它,是否有办法取消该特定图像上的脚本。这是我所拥有的,但它在页面上闪烁:
$( window ).on( "load", function(){
$('.tmblr-full img').each(function(){
var $this = $(this)
$this.attr('src',$this.attr('src').replace('_500.','_540.'))
if ($(this).width() >= 500) {
$(this).css({'width' : 'auto', 'height' : 'auto'});
}
})
$('.tmblr-full img').error(function(){
var $this = $(this)
$this.attr('src',$this.attr('src').replace('_540.','_500.'))
})
});
Here is a JSFiddle与原代码(不包括我添加的错误函数)这样你就可以看到问题了。
谢谢!
【问题讨论】:
-
图片不退出,tumbler返回什么url?
-
@TonyHensler 它没有返回任何东西,图像只是破坏了。