這是我的sideThumb
功能與評論。 this.panos
是拇指的數量,而this.translateX
是拇指被移動的像素的數量。設置拇指帶右箭頭極限的最佳方法是什麼?
slideThumbs (direction) { // slide to left or right
const thumbWidth = 160 + 6 // plus padding
const visibleThumbsWidth = thumbWidth * 5 // slide 5 thumbs at a time
// exclude last thumb
const totalThumbsWidth = thumbWidth * (this.panos.length - 1)
if (direction === 'left' && this.translateX !== 0) {
this.translateX += visibleThumbsWidth
}
if (direction === 'right' && this.translateX !== -totalThumbsWidth) {
this.translateX -= visibleThumbsWidth
}
}
最終結果:
transform: translate(-830px, 0px); // clicking the right arrow one time
transform: translate(-1660px, 0px); // and two times
設置左箭頭的限制很簡單:不離開功能運行,如果this.translateX
是0
。設置右箭頭的限制很難。使用-totalThumbsWidth
是不可靠的,因爲11
和14
panos應該帶來相同的結果(使用戶按右箭頭2次)。
什麼是解決這個問題的最好方法是什麼?
編輯:
一些數學,我提出:
6 thumbs => can click right arrow 1 time
11 thumbs => can click right arrow 2 times
16 thumbs => can click right arrow 3 times
5 * x + 1 = 16 // this is how I get x in the third example
x = (this.panos.length - 1)/5 // what to do with this?
我相信我能在數學計算中使用。
可以提供小提琴嗎? – Manticore
使用填充計算中的幻燈片數量 –