简体   繁体   English

使用 jquery 从一张图片淡入另一张图片

[英]Fading from one image to another with jquery

I can change picture by clicking or fade it to another by fadein or fadeout.我可以通过点击或淡入淡出来改变图片或淡入淡出。 But i wanna load a loading.gif in between two pictures.但我想在两张图片之间加载一个loading.gif。

I have:我有:

pic1.jpg
loading.gif
pic2.jpg

Which pic1 is default, And after 4 seconds, i wanna show the loading on pic1 and meanwhile load the pic2 and when pic2 loaded completely, the loading.gif disappears and pic1 fade into pic2.哪个 pic1 是默认的,4 秒后,我想在 pic1 上显示加载,同时加载 pic2,当 pic2 完全加载时,loading.gif 消失,pic1 淡入 pic2。

Do you wanna do like this?你想这样做吗?

 $(function () { flag = true; setInterval(function () { $("img").fadeOut(400, function () { $("img").attr("src", (flag) ? "http://lorempixel.com/400/200/animals/1/" : "http://lorempixel.com/400/200/nature/1/").delay(500).fadeIn(400); flag = !flag; }); }, 2500); });
 .img-holder {width: 400px; height: 200px; background: url("http://www.ajaxload.info/images/exemples/21.gif") center center no-repeat;}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="img-holder"> <img class="img" src="http://lorempixel.com/400/200/nature/1/" /> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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