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.

31 lines
1.3 KiB

5 months ago
  1. // 引入bindingx,此库类似于微信小程序wxs,目的是让js运行在视图层,减少视图层和逻辑层的通信折损
  2. const BindingX = uni.requireNativePlugin('bindingx')
  3. import { os } from '../../libs/function/index';
  4. export default {
  5. methods: {
  6. // 此处不写注释,请自行体会
  7. nvueScrollHandler(e) {
  8. const anchor = this.$refs['u-scroll-list__scroll-view'].ref
  9. const element = {}
  10. if (this.$refs['u-scroll-list__indicator__line__bar']) {
  11. element = this.$refs['u-scroll-list__indicator__line__bar'].ref
  12. }
  13. const scrollLeft = e.contentOffset.x
  14. const contentSize = e.contentSize.width
  15. const { scrollWidth } = this
  16. const barAllMoveWidth = this.indicatorWidth - this.indicatorBarWidth
  17. // 在安卓和iOS上,需要除的倍数不一样,iOS需要除以2
  18. const actionNum = os() === 'ios' ? 2 : 1
  19. const expression = `(x / ${actionNum}) / ${contentSize - scrollWidth} * ${barAllMoveWidth}`
  20. BindingX.bind({
  21. anchor,
  22. eventType: 'scroll',
  23. props: [{
  24. element,
  25. property: 'transform.translateX',
  26. expression
  27. }]
  28. })
  29. }
  30. }
  31. }