我的网站上的商店页面显示产品的“全长”图像,然后在悬停时显示“特写”图像。
我想随机化这一点,这样对于某些产品来说,“特写”是在加载时显示的,而对于另一些产品,则是“全长”。在每一页上都有这样的随机。
“全长”图像总是命名为xxx1.jpg,而“特写”图像则是xxx2.jpg。
<li>
<div id="product">
<img class="full-length" src="/image-1.jpg"/>
<img class="close-up" src="/image-2.jpg"/>
</div>
</li>我想我需要一个随机数发生器,介于1到2之间,然后第二个图像是第一个图像不是的。
任何帮助,真诚和非常感谢。
发布于 2017-09-10 13:00:06
我认为这可以帮助you.Java脚本代码:
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function onloadSetImage()
{
document.getElementById('product1').src='image-'+getRandomArbitrary(1,5);
}html (onload can check here):
<body onload="onloadSetImage();"/>
<li>
<img id="product1" src=""/>
</li>
</body>https://stackoverflow.com/questions/46140819
复制相似问题