13
13
:class =" ['ohyeah-scroll-vertical-track-h',{'disabled': !isShowH},{'show': barHDown },{'left': left}]" >
14
14
<div @mousedown.stop =" onBarMousedown($event, 1)"
15
15
ref =" ohyeahbarh"
16
- :style =" `transition:transform ${transSpeed}ms,width 250ms,height 250ms;background-color:${thumbColor};width:${(hoverH || barHDown )? breadth + 4 : breadth}px;height: ${barHTall}px;transform: translateY(${barHScrollTop}px);border-radius:${breadth}px`" ></ div >
16
+ :style =" `transition:transform ${transSpeed}ms,width 250ms,height 250ms;background-color:${thumbColor};width:${(hoverH || barHDown )? breadth + 4 : breadth}px;height: ${barHTall}px;transform: translateY(${barHScrollTop}px);border-radius:${breadth}px`" / >
17
17
</div >
18
18
<!-- 横向滚动条 -->
19
19
<div v-if =" !noHor"
24
24
:class =" ['ohyeah-scroll-vertical-track-w',{'disabled': !isShowW},{'show': barWDown },{'top': top}]" >
25
25
<div @mousedown.stop =" onBarMousedown($event,2)"
26
26
ref =" ohyeahbarw"
27
- :style =" `transition:transform ${transSpeed}ms,height 250ms,width 250ms;background-color:${thumbColor};height:${(hoverW || barWDown) ? breadth + 4 : breadth}px;width: ${barWTall}px;transform: translateX(${barWScrollLeft}px)`" ></ div >
27
+ :style =" `transition:transform ${transSpeed}ms,height 250ms,width 250ms;background-color:${thumbColor};height:${(hoverW || barWDown) ? breadth + 4 : breadth}px;width: ${barWTall}px;transform: translateX(${barWScrollLeft}px)`" / >
28
28
</div >
29
29
<!-- 默认内容 -->
30
30
<div ref =" ohyeahbody"
40
40
</template >
41
41
<script >
42
42
import ElementResizeDetectorMaker from " element-resize-detector" ;
43
-
44
43
export default {
45
44
name: " ohyeah" ,
46
45
data () {
47
46
return {
48
- isMobile: / (android)| (iphone)| (symbianos)| (windows phone)| (ipad)| (ipod)/ .test (
49
- navigator .userAgent .toLowerCase ()
50
- ),
47
+ isMobile: false ,
51
48
observer: null , // 监听变化
52
49
isShowH: false , // 是否显示垂直滚动条
53
50
isShowW: false , // 是否显示横向滚动条,
@@ -71,11 +68,7 @@ export default {
71
68
hoverW: false , // W悬浮
72
69
transSpeed: 250 , // 过渡的速度
73
70
timer: 0 ,
74
- slow:
75
- navigator .userAgent .indexOf (" Firefox" ) >= 0 &&
76
- navigator .userAgent .indexOf (" Windows" ) >= 0
77
- ? 8
78
- : 0.2 // 减缓滚轮的速度,太快了,windows版本的火狐特殊处理
71
+ slow: 0.22
79
72
};
80
73
},
81
74
props: {
@@ -89,10 +82,19 @@ export default {
89
82
autoHide: { type: Boolean , default: true }, // 是否自动隐藏滚动条
90
83
minLength: { type: Number , default: 20 }, // 滑块最小长度
91
84
width: { type: [Number , String ], default: " 100%" }, // ohyeah容器宽度
92
- height: { type: [Number , String ], default: " 100%" } // ohyeah容器高度
85
+ height: { type: [Number , String ], default: " 100%" }, // ohyeah容器高度
86
+ resizeObject: { type: Boolean , default: false } // resize模式,默认scroll
93
87
},
94
88
mounted () {
95
89
// 监听内部宽高变化,用于调整滚动条大小和位置
90
+ this .isMobile = / (android)| (iphone)| (symbianos)| (windows phone)| (ipad)| (ipod)/ .test (
91
+ navigator .userAgent .toLowerCase ()
92
+ );
93
+ this .slow =
94
+ navigator .userAgent .indexOf (" Firefox" ) >= 0 &&
95
+ navigator .userAgent .indexOf (" Windows" ) >= 0
96
+ ? 8
97
+ : 0.22 ;
96
98
if (this .isMobile ) {
97
99
return ;
98
100
}
@@ -112,7 +114,8 @@ export default {
112
114
if (window .ResizeObserver ) {
113
115
this .observer .disconnect ();
114
116
} else {
115
- this .observer .uninstall ();
117
+ this .observer .uninstall (this .$refs .ohyeahbody );
118
+ this .observer .uninstall (this .$refs .ohyeahbox );
116
119
}
117
120
this .observer = null ;
118
121
},
@@ -192,9 +195,9 @@ export default {
192
195
this .observer .observe (this .$refs .ohyeahbody );
193
196
this .observer .observe (this .$refs .ohyeahbox );
194
197
} else {
195
- this .observer = ElementResizeDetectorMaker ({
196
- strategy: " scroll"
197
- } );
198
+ this .observer = ElementResizeDetectorMaker (
199
+ this . resizeObject ? null : { strategy: " scroll" }
200
+ );
198
201
this .observer .listenTo (this .$refs .ohyeahbody , this .callback );
199
202
this .observer .listenTo (this .$refs .ohyeahbox , this .callback );
200
203
}
0 commit comments