[英]Fade one image into another.
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<img id='slideshow' src="1.jpg">
<script>
$("#slideshow").fadeIn("slow", function() {
$("#slideshow").attr('src','2.jpg');
});
</script>
</body>
我正在尝试制作一个jQuery脚本,其中1.jpg淡出,2.jpg淡入但我只看到1.jpg并且它停留在那里
尝试这样的事情:
$( "#slideshow" ).fadeOut( "slow", function( ) {
$( "#slideshow" ).prop('src','2.jpg').fadeIn('slow');
});
这将淡出原始图像,一旦淡入淡出完成,更改图像的src属性,然后开始淡入新图像。
根据你所说的..如果我理解正确...虽然我可能会弄错,但似乎你要求1淡出......改为2 ......并且淡入2? 如果是这样,这不起作用吗?
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<img id='slideshow' src="1.jpg">
<script>
$("#slideshow").fadeOut();
$("#slideshow").attr('src','2.jpg');
$("#slideshow").fadeIn();
</script>
</body>
这是简单的版本,当然我会假设它会被放在.on()
事件之类的函数中等等......
这适用于您添加的许多图像。 只要他们有类slideshow
。
这也允许您交叉淡化图像。 请参阅下面的非交叉淡化。
看到这个小提琴。
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<img id='slideshow' src="1.jpg">
<img id='slideshow' src="2.jpg">
<script type="text/javascript">
$(document).ready(function () {
$(".slideshow").hide();
var item = 0;
loop = setInterval(function() {
if(item == $(".slideshow").size()) {
item = 0;
}
$(".slideshow").fadeOut(300);
$(".slideshow").eq(item).fadeIn(300);
item++;
}, 3000);
});
</script>
</body>
非交叉淡入淡出
$(".slideshow").fadeOut(300, function () {
$(".slideshow").eq(item).fadeIn(300);
});
UPDATE
您可以添加以下css以使图像显示在同一空间中。
.slideshow { position:absolute; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.