gpt4 book ai didi

javascript - 基本 JQuery 推子

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:33 24 4
gpt4 key购买 nike

我在 JQuery 中创建了这个简单的推子,

它运行良好,只是第一个图像褪色两次,我该如何解决这个问题?这是代码:

$(document).ready(function(){

var count = 0;
var images = ["http://kingofwallpapers.com/fantasy/fantasy-005.jpg",
"https://s-media-cache-ak0.pinimg.com/originals/57/48/b0/5748b075637cb4e085d5d1d1b5990624.jpg",
"http://www.mrwallpaper.com/wallpapers/Fantasy-City.jpg",
"https://galeri14.uludagsozluk.com/855/kad%C4%B1n_1271171.jpg"];
var image = $(".fader");

image.css("background-image","url("+images[count]+")");

setInterval(function(){
image.fadeOut(500, function(){
image.css("background-image","url("+images[count++]+")");
image.fadeIn(500);
});
if(count == images.length)
{
count = 0;
}
},5000);

});
.fader {
position: absolute;
height: 100%;
width: 100%;
left:0;
top:0;
z-index: -99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fader"></div>

最佳答案

替换

  image.css("background-image","url("+images[count]+")");

  image.css("background-image","url("+images[count++]+")");

$(document).ready(function(){

var count = 0;
var images = ["http://kingofwallpapers.com/fantasy/fantasy-005.jpg",
"https://s-media-cache-ak0.pinimg.com/originals/57/48/b0/5748b075637cb4e085d5d1d1b5990624.jpg",
"http://www.mrwallpaper.com/wallpapers/Fantasy-City.jpg",
"https://galeri14.uludagsozluk.com/855/kad%C4%B1n_1271171.jpg"];
var image = $(".fader");

image.css("background-image","url("+images[count++]+")");

setInterval(function(){
image.fadeOut(500, function(){
image.css("background-image","url("+images[count++]+")");
image.fadeIn(500);
});
if(count == images.length)
{
count = 0;
}
},5000);

});
.fader {
position: absolute;
height: 100%;
width: 100%;
left:0;
top:0;
z-index: -99;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fader"></div>

关于javascript - 基本 JQuery 推子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43435893/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com