这是我的带注释的
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
个全景图应该带来相同的结果(使用户能够按两次右箭头)。
我应该如何最好地解决这个问题?
编辑:
我做了一些数学计算:
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?
我确定我可以在数学计算中使用这个。