First of all, you need to define the direction of each images.
And then if one reaches to end, change the direction to backward.
To give you the basic workflow, you can refer to the following code.
const image1 = {
el: document.querySelector('.image1'),
direction: 'left'
}
const image2 = {
el: document.querySelector('.image2'),
direction: 'down'
}
const image3 = {
el: document.querySelector('.image3'),
direction: 'right'
}
let timer = null;
function onStop() {
if (timer) {
clearInterval(timer);
timer = null;
}
}
function onResume() {
timer = setInterval(() => {
moveImage();
}, 5);
}
function moveImage() {
// here you can check if the images reach to end, then change the direction, otherwise, move the image according to the direction.
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…