我有一个代码可以在页面加载时随机化 div 元素中的背景图像,但它似乎不起作用。
JS 部分:
function Randomize() {
var images = new Array("<?php echo SITE_URL?>/lib/skins/flyeuro/images/banners/ban.ner1.jpg","<?php echo SITE_URL?>/lib/skins/flyeuro/images/banners/banner2.jpg");
var imageNum = Math.floor(Math.random() * images.length);
document.getElementById("banner").style.backgroundImage = "url('" + images[imageNum] + "') repeat scroll center center rgb(0, 0, 0)";
}
window.onload = Randomize;
HTML:
<div id="banner"></div>
CSS:
div#banner {
background: url("../images/banners/banner1.jpg");
width: 100%;
height: 270px;
z-index: 1;
margin-bottom: 25px;
-webkit-box-shadow: 0px 2px 15px 2px ;
box-shadow: 0px 2px 15px 2px ;
}