<script>
let step = 10, //
index = 0, //
flag = -1, //
dis = 0, //
width = 400, //
num = 5; //
const pics = ["../one.jpg", "../two.jpg", "../three.jpg", "../four.jpg", "../five.jpg"];
let wrapper = document.querySelector(".wrapper");
let menu = document.querySelector(".menu");
//
pics.forEach(val => {
let img = document.createElement("img");
let smallImg = document.createElement("img");
img.src = val;
smallImg.src = val;
wrapper.appendChild(img);
menu.appendChild(smallImg);
});
//
function addPic() {
pics.forEach(val => {
let img = document.createElement("img");
img.src = val;
wrapper.appendChild(img);
});
}
//style
function getStyle(ele, cssname) {
if (window.getComputedStyle) {
return window.getComputedStyle(ele)[cssname];
} else {
return ele.currentStyle[cssname];
}
}
//
function pace() {
let curPos = parseInt(getStyle(wrapper, "left"));
console.log("pace");
console.log(to);
console.log(curPos);
wrapper.style.left = curPos + flag * step + "px";
dis += flag * step;
//
if (Math.abs(to - dis) < step) {
wrapper.style.left = to + "px";
dis = to;
indexPP;
clearInterval(pacer);
// setTimeout(() => {
// timer = setInterval(pace, 100);
// }, 2000);
} else {
wrapper.style.left = curPos + flag * step + "px";
dis += flag * step;
}
}
//
function move(direction) {
let to = -width * index; //
// -1-left 1-right
flag = direction === 1 ? 1 : -1;
console.log(to);
console.log(dis);
pacer = setInterval(pace, 100);
}
//
function auto() {
addPic();
indexPP;
move(flag);
}
auto();
</script>
browsers keep prompting
Uncaught ReferenceError: to is not defined at pace
but isn"t to defined in move ()?
I don"t know what"s wrong with it. Ask the bosses for advice.