我想要在每次頁面重新加載時隨機加載圖像。然而,要使用的代碼不能只從特定目錄中選擇一張照片,但它需要每次隨機選擇一個預設路徑到不同目錄中的不同照片。隨機加載不在同一目錄內的圖像
預設路徑有這些:
一些代碼在這裏下面。下面的代碼中已經顯示的照片應該被取出。有它在那裏,現在可以看到一些東西。
#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