gpt4 book ai didi

javascript - 显示随机分区

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

我正在尝试为我的主页随机分配这些 div 的负载。我有一些使它变得困难的特定 css,否则我会做随机化图像的众多建议之一。感谢您的帮助!

<div class="banner-images">

<div class="feature" style="background-image: url(images/typewriter.png)">
<img class="hero-poster" src="images/typewriter.png" />

<div class="hero-decoration">
<div class="side-l"></div>
<div class="arrow"><img alt="Hero-triangle" src="images/triangle.png" /></div>
<div class="side-r"></div>
</div>
</div>

<div class="feature" style="background-image: url(images/printing.png)">
<img class="hero-poster" src="images/printing.png" />

<div class="hero-decoration">
<div class="side-l"></div>
<div class="arrow"><img alt="Hero-triangle" src="images/triangle.png" /></div>
<div class="side-r"></div>
</div>
</div>

<div class="feature" style="background-image: url(images/newspaper.png)">
<img alt="Releaser" class="hero-poster" src="images/newspaper.png" />

<div class="hero-decoration">
<div class="side-l"></div>
<div class="arrow"><img alt="Hero-triangle" src="images/triangle.png" /></div>
<div class="side-r"></div>
</div>
</div>
</div>

最佳答案

这是您可以做到的一种方法:

$(document).ready(function() {
var rand = Math.floor(Math.random()*3);
var visibleDiv = $('.feature')[rand];
$(visibleDiv).show();
});

生成一个随机数,然后显示与该数字一致的元素。

JSFiddle

关于javascript - 显示随机分区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30984794/

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