因此,我有一个脚本,可在单击缩略图时更改主图像src。一切都很好,除了单击图像时偶尔不立即加载图像。
从本质上来说,我怎么知道何时从src更改中加载新图像。
这是我更改源代码的代码行:
$thumbnail_image_src = $(this).find('.thumbnail-image').attr("data-full");
最佳答案
将处理程序绑定到img标签('load')的this JSFiddle事件
$(this).find('.thumbnail-image').each(function() {
$(this).load(function() {
alert('image has changed and loaded');
})
.error(function() {
alert('image has failed to load');
}).attr('src', $(this).attr('data-full'));
});
这些功能将在适当的事件时触发。请享用!