[英]changing img src using jquery in firefox
I created a simple image gallery where I have a large picture in the middle and thumbnails below: 我创建了一个简单的图片库,中间有一张大图片,下面是缩略图:
<img class="primary-image" src="example.jpeg">
<div class="thumbnails">
<img class="thumbnail" src="red.jpeg">
<img class="thumbnail" src="blue.jpeg">
<img class="thumbnail" src="green.jpeg">
</div>
I have the following click handler on the thumbnails: 我在缩略图上有以下点击处理程序:
$('.thumbnail').click(function() {
var src = $(this).attr('src');
$('.primary-image').attr('src', src);
});
This is working fine in chrome, but in Firefox, the image loads slowly from top to bottom, giving an ugly "transition" which is not meant to be there. 这在chrome中可以正常工作,但是在Firefox中,图像从上到下缓慢加载,产生了一个丑陋的“过渡”,这本来就不应该存在。
What is going on? 到底是怎么回事?
UPDATE 更新
I now noticed that what is happening is that the browser does not display the new image. 我现在注意到正在发生的事情是浏览器未显示新图像。 And also that it only happens with specific pictures:
并且它仅在特定图片中发生:
Have you tried to preload the image? 您是否尝试过预加载图像? Maybe the image was cached in Chrome, but not in FireFox.
也许图片是在Chrome中缓存的,但不是在FireFox中缓存的 。
There is someone on StackOverflow who posted some code to easily preload images. StackOverflow上有人发布了一些代码以轻松地预加载图像。 Please take a look at Preloading images with jQuery
请看一下使用jQuery预加载图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.