gpt4 book ai didi

javascript - 随机淡入淡出

转载 作者:行者123 更新时间:2023-11-28 01:49:24 24 4
gpt4 key购买 nike

我需要下面的每个 Spark 随机淡入和淡出,但不是一次全部淡出。一次1-2个就可以了。另外,我不希望“打包”图像褪色。我不希望 Spark 因悬停等功能而淡入/淡出。我还需要它们全部在 5 秒后消失。请帮忙,我已经尝试了一切,无法弄清楚..我是网络开发和 javascript 的新手。

这是我发现的一个 fiddle ,我希望它与此类似,我尝试编辑代码。我现在很困惑。

http://jsfiddle(dot)net/maniator/rcts4/- Fiddle(我不能上传超过 2 个链接,请去掉 http://后面的空格并将“(点)”替换为 .查看 fiddle 。

http://pastebin.com/DkDjU0qS - HTML http://pastebin.com/Zr1vjafn - CSS

最佳答案

HTML

<html>
<head>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<!-- Pack -->
<img id="pack" src="http://cloud.attackofthefanboy.com/wp-content/uploads/2013/07/fifa14pack.png">

<!-- Sparkles-->
<div id="sparkles">

<img id="sparkle1" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle2" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle3" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle4" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle5" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle6" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle7" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">

<img id="sparkle8" src="http://www.clker.com/cliparts/w/L/F/v/7/8/sparkle-md.png">
</div>
<script>

// Define a random integer function
function random(n) {
return Math.floor(Math.random() * n);
}

// Define some variables, hide all images and show just one of them.
var transition_time = 500;
var waiting_time = 500;
var images = $('div#sparkles img');
var n = images.length;
var current = random(n);

images.hide();
images.eq(current).show();

// Periodically, we fadeOut the current image and fadeIn a random one
var interval_id = setInterval(function () {
images.eq(current).fadeOut(transition_time, function () {
current = random(n);
images.eq(current).fadeIn(transition_time);
});
}, 2 * transition_time + waiting_time);

</script>
</body>
</html>

CSS

 html, body {
width: 100%;
height: 100%;

background-color: white;
}

#pack {
position: absolute;
top: 50%;
left: 50%;
height: 300px;
width: 200px;
margin-top: -100px;
margin-left: -100px;
}

#sparkle1 {
position: absolute;
top: -8%;
left: 50%;
height: 140px;
width: 150px;
}

#sparkle2 {
position: absolute;
top: 90%;
left: 57%;
height: 180px;
width: 155px;
}

#sparkle3 {
position: absolute;
top: 94%;
left: 29%;
height: 140px;
width: 115px;
}

#sparkle4 {
position: absolute;
top: 25%;
left: 86%;
height: 150px;
width: 123px;
}

#sparkle5 {
position: absolute;
top: 20%;
right: 83%;
height: 145px;
width: 118px;
}

#sparkle6 {
position: absolute;
top: 79%;
right: 82%;
height: 150px;
width: 120px;
}

#sparkle7 {
position: absolute;
top: 52%;
right: 85%;
height: 150px;
width: 130px;
}

#sparkle8 {
position: absolute;
top: 50%;
left: 85%;
height: 180px;
width: 160px;
}

#sparkles {
position: absolute;
top: 50%;
left: 50%;

width: 500px;
height: 500px;
margin-top: -250px;
margin-left: -250px;
}

这是更新的 JSFiddle

希望这对您有所帮助。

关于javascript - 随机淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20915750/

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