You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 引入bindingx此库类似于微信小程序wxs目的是让js运行在视图层减少视图层和逻辑层的通信折损
const BindingX = uni.requireNativePlugin('bindingx')
export default {
methods: {
// 此处不写注释,请自行体会
nvueScrollHandler(e) {
const anchor = this.$refs['u-scroll-list__scroll-view'].ref
const element = this.$refs['u-scroll-list__indicator__line__bar'].ref
const scrollLeft = e.contentOffset.x
const contentSize = e.contentSize.width
const { scrollWidth } = this
const barAllMoveWidth = this.indicatorWidth - this.indicatorBarWidth
// 在安卓和iOS上需要除的倍数不一样iOS需要除以2
const actionNum = uni.$u.os() === 'ios' ? 2 : 1
const expression = `(x / ${actionNum}) / ${contentSize - scrollWidth} * ${barAllMoveWidth}`
BindingX.bind({
anchor,
eventType: 'scroll',
props: [{
element,
property: 'transform.translateX',
expression
}]
})
}
}
}