【问题标题】:Random product thumbnails随机产品缩略图
【发布时间】:2017-09-10 12:43:59
【问题描述】:

我网站上的商店页面显示产品的“全长”图像,然后在悬停时显示“特写”图像。

我希望随机化,这样对于某些产品,加载时会显示“特写”,而对于其他产品,则会显示“全长”。并在每次页面加载时随机显示。

“全长”图像始终命名为 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 之间的随机数生成器,然后让第二张图片成为第一张图片的样子不是

任何帮助,真诚且非常感激。

【问题讨论】:

  • 你到底想做什么?想要显示给定图像中的一张图像? PHP?

标签: image random


【解决方案1】:

我认为这可以帮助你。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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2018-04-28
    • 2023-03-23
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多