项目场景:
淘宝式轮播图 |
问题描述:
手动切换太快,或者设置定时间时间太短,切换都会出现的跳转BUG,
BUG源码:
JS:
class swiper {
constructor() {
this.ullis = this.$('ul li', true);
this.ul = this.$('ul');
this.ol = this.$('ol');
this.screen = this.$('#screen');
this.createIndex();
this.box = this.$('#box');
this.imgW = this.ullis[0].offsetWidth;
this.index = 0;
this.times;
this.timess;
this.box.addEventListener('mouseover', this.overFn.bind(this));
this.box.addEventListener('mouseout', this.outFn.bind(this));
// 给左右按钮设置点击
this.$('#left').addEventListener('click', this.leftClick.bind(this));
this.$('#right').addEventListener('click', this.rightClick.bind(this));
this.autoplay();
}
// 添加序列号
createIndex() {
let length = this.ullis.length;
for (var i = 0; i < length; i++) {
let li = document.createElement('li');
li.innerHTML = i + 1;
i == 0 && (li.className = 'current');
this.ol.appendChild(li);
li.addEventListener('click', this.olliclick.bind(this));
}
this.olli = this.$('ol li'