window.addEventListener('load',function(){
var arrowl = document.querySelector('.arrow-l');
var arrowr = document.querySelector('.arrow-r');
var focus = document.querySelector('.focus');
focus.addEventListener('mouseenter',function(){
arrowl.style.display = 'block';
arrowr.style.display = 'block';
clearInterval(timer);
timer = null;
})
focus.addEventListener('mouseleave',function(){
arrowl.style.display = 'none';
arrowr.style.display = 'none';
timer = setInterval(function(){
arrowr.click();
},2000)
})
var ol = document.querySelector('.circle');
var ulImg = document.querySelector('.ulImg');
for(var i = 0 ; i < ulImg.children.length; i++){
var li = document.createElement('li');
var index = li.setAttribute('index',i);
ol.appendChild(li);
var imgOffWidth = focus.offsetWidth;
li.addEventListener('click',function(){
if(true) {
for(var j = 0; j< ol.children.length; j++){
ol.children[j].className = '';
}
this.className = 'current';
index = this.getAttribute('index');
num = index;
circle = index;
antimer(ulImg,-index * imgOffWidth)
}
for(var j = 0; j< ol.children.length; j++){
ol.children[j].className = '';
}
this.className = 'current';
index = this.getAttribute('index');
num = index;
circle = index;
antimer(ulImg,-index * imgOffWidth)
})
}
ol.children[0].className = 'current';
var first = ulImg.children[0].cloneNode(true);
ulImg.appendChild(first);
var num = 0;
var circle = 0;
var flag = true;
arrowr.addEventListener('click',function(){
if(flag){
flag = false;
if(num === ulImg.children.length - 1) {
ulImg.style.left = 0;
num = 0;
}
num++;
antimer(ulImg,-num * imgOffWidth,function(){
flag = true;
});
circle++;
if(circle > ol.children.length-1) {
circle = 0;
}
current();
}
})
arrowl.addEventListener('click',function(){
if(flag) {
flag = false;
if(num === 0) {
num = ulImg.children.length - 1;
ulImg.style.left = -num * imgOffWidth + 'px';
}
num--;
antimer(ulImg,-num * imgOffWidth,function(){
flag = true;
});
circle--;
if(circle < 0) {
circle = ol.children.length -1;
}
current();
}
})
function current() {
for(var i = 0; i<ol.children.length; i++){
ol.children[i].className = '';
}
ol.children[circle].className = 'current';
}
var timer = setInterval(function(){
arrowr.click();
},2000)
})