gpt4 book ai didi

javascript - 改变图像的延迟功能

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

我有这段代码可以在更改随机生成的图像时将淡入淡出效果变为黑色:

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

谢谢。

最佳答案

如果这些是固定的(预先确定的)图像文件名,那么您可以像这样使用标准 CSS 动画...

<!DOCTYPE html>
<head>

<style type="text/css">

.Container {
position: absolute;
left: 50px;
top: 50px;
width: 300px;
height: 300px;
background-image: url("");
background-position: 0% 0%;
background-size: 100% 100%;
animation: AnimText 3s linear 0s infinite alternate none;
}

@keyframes AnimText {

0% {opacity:1; background-image: url("C:/Users/PackardBell/Pictures/Penguins.jpg");}

50% {opacity:0.5; background-image: url("C:/Users/PackardBell/Pictures/Lighthouse.jpg");}

100% {opacity:0; background-image: url("C:/Users/PackardBell/Pictures/Jellyfish.jpg");}
}

</style>
</head>

<body>

<div class="Container"></div>

</body>
</html>

关于javascript - 改变图像的延迟功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48235321/

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