jQuery 淡入淡出两个图像没有白色

标签 jquery image fade

我想淡化图像,而图像之间没有白色转移。

HTML:

<div class="image">
  <span><img src="1.jpg"></span>
</div>

jQuery:

$('.image > span > img').fadeOut(1000, function() {
  $('.image > span > img').attr('src', images[i]);
  $(this).fadeIn(1000);
});

这可行,但变化之间会出现白色褪色。 Images 数组包含图像源。 我找到了这个http://jsfiddle.net/byB6L/但我无法更新我的代码来使用它。

最佳答案

这应该会给你一个想法:

var c = 0,                  // Counter index
    $img = $('.image img'), // Get images
    n = $img.length;        // How many images?

$img.eq(c).show();          // Show c one

(function loop() {          // Recursive infinite loop
    $img.delay(1000).fadeOut(800).eq(++c%n).fadeIn(800, loop);
}()); 
.image{
  position:relative;
}
.image img{
  position:absolute;
  top:0px; 
  display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="image">
  <img src="http://placehold.it/300x150/bf0?text=Apples" alt="" />
  <img src="http://placehold.it/300x150/0bf?text=and" alt="" />
  <img src="http://placehold.it/300x150/fb0?text=Pears" alt="" />
</div>

关于jQuery 淡入淡出两个图像没有白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30529582/

相关文章:

jquery - 显示和隐藏内容

javascript - 警告来自被克隆短语包裹的克隆链接的值

jquery - 元素上的淡出/淡入图像

javascript - 添加淡入淡出过渡效果和自动图像变化

javascript - PHP - 无法使用获取的数据

javascript - 当元素底部位于屏幕中时的 jQuery

CSS 缩放多个图像以适应视口(viewport)并保持纵横比

image - 快速确定图像是照片还是绘图

objective-c - 视网膜 iPad 上的非视网膜图像

jQuery FadeIn 在 Android 移动 Chrome 中无法正常工作