我想要在每次页面重新加载时随机加载图像。然而,要使用的代码不能只从特定目录中选择一张照片,但它需要每次随机选择一个预设路径到不同目录中的不同照片。随机加载不在同一目录内的图像
预设路径有这些:
一些代码在这里下面。下面的代码中已经显示的照片应该被取出。有它在那里,现在可以看到一些东西。
#myContainer {
position: absolute;
height: 150px;
width: 150px;
background-color: #ffffff;
margin-top: 30px;
border-radius: 75px;
overflow: hidden;
border-style: solid;
border-width: 8px;
border-color: #ffffff;
padding: 8px;
}
#myPhoto {
width: 150px;
height: auto;
margin-top: -8px
}
<div id="myContainer">
<img id="myPhoto" src=" https://static.webshopapp.com/shops/054833/files/097160429/eddyhilhorst-fotelphotographycoursesandtours-no-lo.jpg" />
</div>
感谢Teemu,一直在寻找,但只能找到一个使用驻留在同一目录内的图像代码。 – Eddy
'var images = [“https://static.webshopapp.com/shops/054833/files/097622657/eddy-hilhorst-fotel-photography-courses-tours.jpg","https://static.webshopapp.com /shops/054833/files/097622663/hiromi-fujii-fotel-photography-courses-tours.jpg","https://static.webshopapp.com/shops/054833/files/097622666/jungsoon-suh-fotel-photography ''并且有'document.getElementById(“myPhoto”)。src = images [Math.floor(Math.random()* images.length)];' – mplungjan
这些示例使用数组存储图像的相对路径,对吧?什么阻止你存储绝对地址? – Teemu