Open ViYaYaYa opened 5 years ago
因为transform的translateY100%会露出一大堆空白的东西,所以改由js实现,因此列表的transform: translate(-${scrollLineHeight * scrollIndex}px)
translate(-${scrollLineHeight * scrollIndex}px)
doScroll() { const rBox = this.$refs.box const rList = this.$refs.list if (!rBox || !rList) return if (rList.offsetHeight > rBox.clientHeight) { let lineH = this.scrollLineHeight = rList.firstChild.offsetHeight let boxH = rBox.clientHeight let listH = rList.offsetHeight const cb = () => { const i = ++this.scrollIndex if (i * lineH + boxH >= listH) { // 重新计算 this.scrollIndex = 0 lineH = this.scrollLineHeight = rList.firstChild.offsetHeight boxH = rBox.clientHeight listH = rList.offsetHeight } scrollTimer = setTimeout(cb, 1500) } cb() } else { clearTimeout(scrollTimer) scrollTimer = null this.scrollIndex = 0 } }
因为transform的translateY100%会露出一大堆空白的东西,所以改由js实现,因此列表的transform:
translate(-${scrollLineHeight * scrollIndex}px)