3
3
:style =" `width:${theWidth};height:${theHeight}`"
4
4
class =" ohyeah-scroll-box" >
5
5
<!-- 纵向滚动条 -->
6
- <div v-if =" !noVer"
6
+ <div v-if =" !noVer && !isMobile "
7
7
@mousedown.stop =" onTrackMousedown($event,1)"
8
8
@mouseenter.stop =" hoverH = true"
9
9
@mouseleave.stop =" hoverH = false"
14
14
:style =" `transition: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`" />
15
15
</div >
16
16
<!-- 横向滚动条 -->
17
- <div v-if =" !noHor"
17
+ <div v-if =" !noHor && !isMobile "
18
18
@mousedown.stop =" onTrackMousedown($event,2)"
19
19
@mouseenter.stop =" hoverW = true"
20
20
@mouseleave.stop =" hoverW = false"
26
26
</div >
27
27
<!-- 默认内容 -->
28
28
<div :ref =" `ohyeahbody-${id}`"
29
- :class =" ['ohyeah-scroll-body',{'isSmooth': needSmooth}]"
29
+ :class =" ['ohyeah-scroll-body',{'isPc': !isMobile},{' isSmooth': needSmooth}]"
30
30
:style =" `${noVer ? 'height:100%;overflow-y:hidden;' : ''} ${noHor ? 'width:100%;overflow-x:hidden;' : ''}`"
31
31
tabindex =" 9999"
32
32
@scroll =" onScrollEvent" >
@@ -45,6 +45,7 @@ export default {
45
45
name: " Ohyeah" ,
46
46
data () {
47
47
return {
48
+ isMobile: false ,
48
49
observer: null , // 监听变化
49
50
isShowH: false , // 是否显示垂直滚动条
50
51
isShowW: false , // 是否显示横向滚动条,
@@ -86,19 +87,29 @@ export default {
86
87
resizeObject: { type: Boolean , default: false } // resize模式,默认scroll
87
88
},
88
89
mounted () {
90
+ // 是否为移动端
91
+ this .isMobile = / (android)| (iphone)| (symbianos)| (windows phone)| (ipad)| (ipod)/ .test (
92
+ navigator .userAgent .toLowerCase ()
93
+ );
94
+ // 是否支持原生平滑滚动,chrome/firefox/opera支持
95
+ this .isBehavior = " scroll-behavior" in document .body .style ;
96
+
89
97
// 监听内部宽高变化,用于调整滚动条大小和位置
90
98
this .callback ();
91
99
this .listenResize ();
92
- // 是否支持原生平滑滚动,chrome/firefox/opera支持
93
- this .isBehavior = " scroll-behavior" in document .body .style ;
94
- // 监听鼠标拖动事件
95
- document .addEventListener (" mousemove" , this .onBarDragMove , false );
96
- document .addEventListener (" mouseup" , this .onMouseUp , false );
100
+
101
+ if (! this .isMobile ) {
102
+ // 监听鼠标拖动事件
103
+ document .addEventListener (" mousemove" , this .onBarDragMove , false );
104
+ document .addEventListener (" mouseup" , this .onMouseUp , false );
105
+ }
97
106
},
98
107
beforeDestroy () {
99
108
// 卸载鼠标拖动事件
100
- document .removeEventListener (" mousemove" , this .onBarDragMove , false );
101
- document .removeEventListener (" mouseup" , this .onMouseUp , false );
109
+ if (! this .isMobile ) {
110
+ document .removeEventListener (" mousemove" , this .onBarDragMove , false );
111
+ document .removeEventListener (" mouseup" , this .onMouseUp , false );
112
+ }
102
113
103
114
if (window .ResizeObserver ) {
104
115
this .observer .disconnect ();
@@ -525,19 +536,21 @@ export default {
525
536
width : 100% ;
526
537
outline : none ;
527
538
overflow : auto ;
528
- -ms-overflow-style : none !important ;
529
- scrollbar-width : none ;
530
539
-webkit-overflow-scrolling : touch ;
531
540
* {
532
541
-ms-overflow-style : auto ;
533
542
}
543
+ & .isPc {
544
+ -ms-overflow-style : none !important ; // IE/Edge
545
+ scrollbar-width : none ; // Firefox
546
+ // Chrome/Safari/Opera
547
+ & ::-webkit-scrollbar {
548
+ display : none ;
549
+ }
550
+ }
534
551
& .isSmooth {
535
552
scroll-behavior : smooth ;
536
553
}
537
-
538
- & ::-webkit-scrollbar {
539
- display : none ;
540
- }
541
554
}
542
555
543
556
& .mobile {
0 commit comments