简体   繁体   English

在Firefox中使用jQuery更改img src

[英]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: 并且它仅在特定图片中发生:

  • If I scroll down and up quickly the picture changes. 如果我快速上下滚动,图片会改变。 (after clicking thumbnail) (点击缩略图后)
  • If the entire picture canvas is visible, and I do nothing, the previous picture remains there, and the new picture is not displayed. 如果整个画布可见,并且我什么也不做,则前一张图片会保留在那里,而不会显示新图片。 (after clicking thumbnail) (点击缩略图后)
  • If I switch applications and come back to firefox, the new picture is there. 如果我切换应用程序并返回到Firefox,新图片就在那里。 (after clicking thumbnail) (点击缩略图后)
  • If I double click the thumbnail, the picture changes perfectly. 如果我双击缩略图,则图片变化完美。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM