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/14975104/

相关文章:

jQuery 删除特定元素后的最后三个元素

jquery - reactjs - 在 react 树之外公开 react 组件方法

jquery - 如何使用 jquery 触发此页面转换?

php - 如何使用 mysql 刚刚分配的自动增量 id 重命名文件?

javascript - 使用原始 javascript 淡化 HTML 元素

jquery - 带有jquery的parent.window

android - 在 Android 选项卡上,如何在图像下方显示文本?

java - 更新 JLabel 中包含的图像 - 问题

javascript - jquery淡入淡出问题

javascript - 基于滚动条位置的 Div 不透明度