@@ -24,6 +24,14 @@ export default function (Vue, options) {
24
24
} )
25
25
}
26
26
27
+ function isMobile ( ) {
28
+ return navigator . userAgent . indexOf ( 'Windows Phone' ) > - 1
29
+ || navigator . userAgent . indexOf ( 'Android' ) > - 1
30
+ || navigator . userAgent . indexOf ( 'iPad' ) > - 1
31
+ || navigator . userAgent . indexOf ( 'iPhone' ) > - 1
32
+ || navigator . userAgent . indexOf ( 'Mobile' ) > - 1
33
+ }
34
+
27
35
Vue . directive ( 'preload' , {
28
36
bind ( ) {
29
37
this . preLoading = false
@@ -48,8 +56,12 @@ export default function (Vue, options) {
48
56
}
49
57
this . setState ( this . tmp )
50
58
}
51
- _ . on ( this . el , 'mouseover' , this . handleMouseOver )
52
- _ . on ( this . el , 'click' , this . handleClick )
59
+ if ( isMobile ( ) ) {
60
+ _ . on ( this . el , 'touchstart' , this . handleMouseOver )
61
+ } else {
62
+ _ . on ( this . el , 'mouseover' , this . handleMouseOver )
63
+ _ . on ( this . el , 'click' , this . handleClick )
64
+ }
53
65
} ,
54
66
set ( obj ) {
55
67
this . tmp = obj
@@ -64,7 +76,7 @@ export default function (Vue, options) {
64
76
end ( ) {
65
77
this . preLoading = false
66
78
this . hideBar ( )
67
- if ( this . clickToPreload ) {
79
+ if ( this . clickToPreload || isMobile ( ) ) {
68
80
this . setState ( this . tmp )
69
81
this . clickToPreload = false
70
82
}
@@ -86,8 +98,12 @@ export default function (Vue, options) {
86
98
}
87
99
} ,
88
100
reset ( ) {
89
- _ . off ( this . el , 'mouseover' , this . handleMouseOver )
90
- _ . off ( this . el , 'click' , this . handleClick )
101
+ if ( isMobile ( ) ) {
102
+ _ . off ( this . el , 'touchstart' , this . handleMouseOver )
103
+ } else {
104
+ _ . off ( this . el , 'mouseover' , this . handleMouseOver )
105
+ _ . off ( this . el , 'click' , this . handleClick )
106
+ }
91
107
} ,
92
108
unbind ( ) {
93
109
this . reset ( )
0 commit comments