(function(){
var child_arr = document.getElementsByClassName("child");
var len = child_arr.length;
var parent = document.getElementsByClassName("parent")[0];
var move_width = parent.offsetWidth;
var index = 0; // div
function animate() {
var childArr = [].slice.call(child_arr);
if (index === len) {
index = 0;
}
childArr.forEach(function(item, key) {
if (index - key >= 0) {
child_arr[key].style.marginLeft = "-" + move_width * (index - key) + "px";
} else {
child_arr[key].style.marginLeft = move_width * (key - index) + "px";
}
})
indexPP;
}
clearInterval(t);
var t = setInterval(animate, 1000);
})()
I can"t write this way. Why? I still operate on Dom elements. Does anyone know why? Ask for advice