我想找到一種方法,我可以有一個圖像,佔用整個瀏覽器窗口和響應。每次頁面加載時,我都希望背景圖像能夠從我本地選擇的一組照片中進行更改。網頁的隨機背景圖
我已經在這裏嘗試了一些解決方案,但沒有什麼是真正的工作。在HTML我有是:
<div id="container">
<img src="Images/IMG_3764.JPG" alt="An island in the middle of the sea in Turkey" id="backgroundImage">
</div>
的CSS我是:
body {
margin: 0;
}
#container {
width: 100%;
height: 100%;
margin: 0;
}
#backgroundImage {
width: 100%;
position: fixed;
top: 0;
left: 0;
}
html, body {
overflow: none !important;
overflow-x: none !important;
overflow-y: none !important;
}
一,我已經試過了JS的解決方案是這樣的:
var image = new Array();
image[0] = "http://placehold.it/20";
image[1] = "http://placehold.it/30";
image[2] = "http://placehold.it/40";
image[3] = "http://placehold.it/50";
var size = image.length
var x = Math.floor(size*Math.random())
$('#backgroundImage').attr('src',image[x]);
你有你已經試過JavaScript代碼,沒有工作的例子嗎? – Bastiaanus
@Bastiaanus對不起,只是包括了它 –