window.onload = function () {
var oDiv = document.getElementById('banner');
var oUl = oDiv.getElementsByTagName('ul')[0];
var oLi = oUl.getElementsByTagName('li');
var timer = null;
oUl.innerHTML += oUl.innerHTML; // 复制一份内容并追加
oUl.style.width = oLi[0].offsetWidth * oLi.length + 'px';
function startMove() {
timer = setInterval(function () {
if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
oUl.style.left = '0';
}
oUl.style.left = oUl.offsetLeft - 1 + 'px';
}, 30);
}
function pauseMove() {
clearInterval(timer);
}
startMove(); // 开始轮播
oDiv.onmouseover = pauseMove; // 暂停轮播
oDiv.onmouseout = startMove; // 继续轮播
};
轮播图实现
最新推荐文章于 2024-08-14 15:45:18 发布