|
1 | 1 | <template>
|
2 |
| - <div ref='scroller' class='virtual-scroll overhidden' :style='style' v-show='bottom > 5 && virtualPercent < 1' @mousedown.self='barClickHandle'> |
| 2 | + <div ref='scroller' class='virtual-scroll overhidden' :style='style' @mousedown.self='barClickHandle'> |
3 | 3 | <div ref='bar' class="virtual-scroll-bar" :style='barLeft' @mousedown='barMouseDownHandle'></div>
|
4 | 4 | </div>
|
5 | 5 | </template>
|
|
18 | 18 | virtualMouseDownX: 0, // 鼠标按键x坐标
|
19 | 19 | virtualObserver: {},
|
20 | 20 | target: {}, // 滚动元素
|
21 |
| - opacity: false, // 是否需要设置透明 |
| 21 | + // opacity: false, // 是否需要设置透明 |
22 | 22 | bottom: 0, // 底部
|
23 | 23 | iframe: {} // iframe,用来监听resize
|
24 | 24 | }
|
|
45 | 45 | style() {
|
46 | 46 | return {
|
47 | 47 | transform: `translate3d(0px, ${-this.bottom}px, 0px)`,
|
48 |
| - opacity: this.opacity ? 0 : 1 |
| 48 | + opacity: this.bottom > 5 && this.virtualPercent < 1 ? 1 : 0 |
49 | 49 | }
|
50 | 50 | },
|
51 | 51 | scroller() {
|
|
104 | 104 | this.virtualObserver.disconnect()
|
105 | 105 | },
|
106 | 106 | methods: {
|
107 |
| - setOpacityShow: timerFnc(function() { |
108 |
| - this.opacity = false |
109 |
| - }, 100), |
110 | 107 | /**
|
111 | 108 | * @function
|
112 | 109 | * 监听全局滚动, 用来将虚拟滚动条固定在底部
|
113 | 110 | */
|
114 |
| - windowScrollHandle: timerFnc( |
115 |
| - function() { |
116 |
| - const { bottom } = this.target.getBoundingClientRect() |
117 |
| - let result = bottom - document.documentElement.clientHeight |
118 |
| - if (result < 0) { |
119 |
| - result = 0 |
120 |
| - } |
121 |
| - this.bottom = result |
122 |
| - this.setOpacityShow() |
123 |
| - }, |
124 |
| - 100, |
125 |
| - function() { |
126 |
| - this.opacity = true |
| 111 | + windowScrollHandle: function() { |
| 112 | + const { bottom } = this.target.getBoundingClientRect() |
| 113 | + let offsetTop = 0 |
| 114 | + if (this.scroller === window) { |
| 115 | + offsetTop = document.documentElement.clientHeight |
| 116 | + } else { |
| 117 | + offsetTop = |
| 118 | + this.scroller.clientHeight + this.scroller.getBoundingClientRect().top |
127 | 119 | }
|
128 |
| - ), |
| 120 | + let result = bottom - offsetTop |
| 121 | + if (result < 0) { |
| 122 | + result = 0 |
| 123 | + } |
| 124 | + this.bottom = result |
| 125 | + // this.setOpacityShow() |
| 126 | + }, |
129 | 127 | /**
|
130 | 128 | * @function
|
131 | 129 | * 目标滚动时候同步到虚拟滚动条位置
|
|
152 | 150 | this.windowScrollHandle()
|
153 | 151 | this.targetScrollHandle()
|
154 | 152 | },
|
155 |
| - 100, |
156 |
| - function() { |
157 |
| - this.opacity = true |
158 |
| - } |
| 153 | + 100 |
159 | 154 | ),
|
160 | 155 | /**
|
161 | 156 | * @event
|
|
0 commit comments