2024-06-11 carousel實做輪播, 測試dots 的bug記錄

2024-06-11 carousel實做輪播, 測試dots 的bug記錄:

按 click 左右鍵時,出現錯誤:

原來是忘了判斷click元素裏是否含有 “slide-dot” 這個類別

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  addEventListener('click',
function(e){
if (e.target.classList.contains
('slide-dot')) //需加上這個判斷是否含有'slide-dot' 這個類別
{
console.log(e);
console.log('curentIndex: ' +currentIndex);
console.log('dataset-index: '+e.target.dataset.index)
const targetIndex = Number(e.target.dataset.index);
const dist = 100 * (targetIndex-currentIndex);
console.log('dist: '+dist);
skipSlide(targetIndex, dist);
currentIndex = targetIndex;
console.log('currentIndex: '+currentIndex)
}
}
)