<ul class="flex-item" id="carousellist">
<li>
<a class="flex-box">
<p class="flex-item">1sadf</p>
<i class="icon icon-jiantouyou"></i>
</a>
</li>
<li>
<a class="flex-box">
<p class="flex-item">1sadf</p>
<i class="icon icon-jiantouyou"></i>
</a>
</li>
</ul>carousel("carousellist", 3000);
function carousel (id, delay) {
var ele = document.getElementById(id),
speed = 30,
timer = null;
if(ele.childElementCount > 1) {
var move = function () {
clearInterval(timer);
timer = setInterval(function () {
ele.scrollTop++;
if(ele.scrollTop >= ele.offsetHeight) {
clearInterval(timer);
ele.scrollTop = 0;
ele.appendChild(ele.firstElementChild);
setTimeout(move, delay);
}
}, speed)
}
setTimeout(move, delay);
ele.onmouseover = function () {
clearInterval(timer);
}
ele.onmouseout = function () {
setTimeout(move, delay);
}
}
}
添加回答
举报
0/150
提交
取消