【发布时间】:2018-01-12 23:17:49
【问题描述】:
我有这段代码可以在更改随机生成的图像时将淡入淡出效果变为黑色:
var imgs = new Array("https://store.vtxfactory.org/wp-content/uploads/2018/header/1.jpg","https://store.vtxfactory.org/wp-content/uploads/2018/header/2.jpg","https://store.vtxfactory.org/wp-content/uploads/2018/header/3.jpg","https://store.vtxfactory.org/wp-content/uploads/2018/header/4.jpg","https://store.vtxfactory.org/wp-content/uploads/2018/header/5.jpg","https://store.vtxfactory.org/wp-content/uploads/2018/header/6.jpg");
function changeOverlay() {
$('#overlay').animate({opacity: 1,}, 1000);
$('#overlay').animate({opacity: 0,}, 1000);
}
function changeBg() {
var imgUrl = imgs[Math.floor(Math.random()*imgs.length)];
$('#masthead').css('background-image', 'url(' + imgUrl + ')');
}
function changeBackgroundSmoothly() {
$('#masthead').animate(0, changeBg);
}
setInterval(changeOverlay,2000);
setTimeout(changeBackgroundSmoothly,3000);
问题是,图像只在第一次改变。我怎样才能让它像淡入淡出效果一样循环播放?
你可以在这里有一个视觉想法:https://store.vtxfactory.org
谢谢。
【问题讨论】:
-
如果没有工作示例,很难给您答案,但您似乎正在淡入并立即淡出
#overlay,因此它们会相互抵消。 -
你在store.vtxfactory.org有工作示例。
-
@SteveKess 我不知道我是否理解你,你想停止
changeOvelay功能直到图像充电然后重新启动changeOvelay功能还是什么? -
@YouneL 如果你在这里看到store.vtxfactory.org 背景在黑色淡入效果之前切换。我需要使它如下: 1. FadeIn Black > 2. 当 FadeIn Black 为 100% > 3. FadeOut Black 时更改背景图像
-
@YouneL 因此,要使其生效,我首先需要为
changeBackgroundSmoothly函数添加 1 秒的延迟
标签: javascript jquery html css function