// 轮播图
window.addEventListener('load', function() {
//获取元素
var focus = document.querySelector('.focus');
var ul = focus.children[0];
//获得focus宽度
var w = focus.offsetWidth;
//利用定时器自动轮播图图片
var index = 0;
var timer = setInterval(function() {
index++;
var translateX = -index * w;
ul.style.transition = 'all .3s';
ul.style.transform = 'translateX(' +
translateX + 'px)';
}, 2000);
/
//等着我们过渡完成以后,再去判断,监听过渡完成的事件 transitionend
if (index == 3) {
index = 0;
ul.style.transition = 'none';
var translatex = -index * w;
ul.style.transform = 'translateX(' + translatex + 'px)';
} else if (index < 0) {
index = 2;
ul.style.transition = 'none';
var translatex = -index * w;
ul.style.transform = 'translateX(' + translatex + 'px)';
}
});