<script type="text/javascript">
class ShowPic{
imgList
constructor(){
this.imgList = document.querySelector('.imgList')
}
setNum(n){
let per = n/4*100
this.imgList.style.transform = `translateX(-${per}%)`
}
}
let show = new ShowPic()
class Index{
i = 0
inc(){
this.i++
if (this.i>3) {
this.i = 0
}
return this.i
}
dec(){
this.i--
if (this.i<0) {
this.i = 3
}
return this.i
}
}
let index = new Index()
class Time{
timeId
start(){
this.timeId = setInterval(()=>{
show.setNum( index.inc() )
},2000)
}
stop(){
clearInterval(this.timeId)
}
}
let time = new Time()
time.start()
</script>