我在一个网站的所有页面的容器上有一个背景图像,但是主页有两个图像,他们希望这些图像滚动/褪色。
我在这里使用了这个帖子的答案:CSS背景-图像幻灯片,并产生了以下内容:
<script>
var images=new Array('imageurl1','imageurl2');
var nextimage=0;
doSlideshow();
function doSlideshow(){
if(nextimage>=images.length){nextimage=0;}
$('.hometopcontentarea')
.css('background','url("'+images[nextimage++]+'") no-repeat center')
.fadeIn(500,function(){
setTimeout(doSlideshow,1000);
});
}
</script>
<div class="hometopcontentarea col-xs-12 col-sm-12" style="height: 624px; margin-bottom: 20px;">当查看源时,图像路径是正确的,但不巧的是,没有发生任何事情,图像也没有加载。
我做错什么了?
提前谢谢。
发布于 2016-04-21 13:25:46
我想你是在找这个:
var images = [
"http://www.independent.ie/incoming/article29989530.ece/ALTERNATES/h342/Li%20Ann%20Smal%20-App.jpg",
"http://im.rediff.com/news/2015/dec/24tpoty20.jpg"
]
var nextimage = 0;
function doSlideshow(){
if(nextimage>=images.length){nextimage=0;}
$('.hometopcontentarea')
.css({
background: 'url('+ images[nextimage++]+') no-repeat center',
opacity:0,
})
.fadeTo('slow',1);
setTimeout(doSlideshow,4000);
}
doSlideshow();(演示)
fadeIn函数的问题是,您不能淡入1元素2次。一旦它已经可见,你需要重置不透明度,以允许第二个淡入。
https://stackoverflow.com/questions/36769357
复制相似问题