一、确定DIV大小
body { margin: 0; padding: 0; } #event-types { width: 300px; height: 180px; }
二、JS定时刷新背景;
window.onload = function () { var imgs = ["images/event0.jpg", "images/event1.jpg", "images/event2.jpg"]; var i = 0; var head = document.getElementById("event-types"); head.style.background = "url(images/event0.jpg)"; function time() { i++; i = i % 3; head.style.background = "url(" + imgs[i] + ")"; } setInterval(time, 6 * 1000); }