File tree 2 files changed +30
-8
lines changed 2 files changed +30
-8
lines changed Original file line number Diff line number Diff line change 25
25
<!-- Add "scoped" attribute to limit CSS to this component only -->
26
26
<style scoped>
27
27
28
- </style>
28
+ </style>
Original file line number Diff line number Diff line change 48
48
maskOpacity: {
49
49
default: .5
50
50
},
51
- maskClass: {}
51
+ maskClass: {},
52
+ delayIn: {
53
+ type: Number ,
54
+ default: 0
55
+ },
56
+ delayOut: {
57
+ type: Number ,
58
+ default: 0
59
+ }
52
60
},
53
61
data () {
54
62
return {
64
72
zoomPosition: {
65
73
x: 0 ,
66
74
y: 0
67
- }
75
+ },
68
76
}
69
77
},
70
78
computed: {
115
123
},
116
124
methods: {
117
125
handleOver () {
118
- this .zoomShow = true ;
119
- this .imgRect = this .$refs .img && this .$refs .img .getBoundingClientRect ();
126
+ if (this .delayIn === 0 ) {
127
+ this .zoomShow = true ;
128
+ this .calcZoomSize ();
129
+ }else {
130
+ setTimeout (() => {
131
+ this .zoomShow = true ;
132
+ this .calcZoomSize ();
133
+ },this .delayIn )
134
+ }
135
+ },
136
+ calcZoomSize () {
120
137
this .$nextTick (() => {
138
+ this .imgRect = this .$refs .img && this .$refs .img .getBoundingClientRect ();
121
139
this .maskRect = this .$refs .mask && this .$refs .mask .getBoundingClientRect ();
122
140
123
141
// 计算大图宽高
124
142
this .zoomImgWidth = (this .imgRect .width / this .maskRect .width ) * this .zoomWidth ;
125
143
this .zoomImgHeight = (this .imgRect .height / this .maskRect .height ) * this .zoomHeight ;
126
144
})
127
-
128
-
129
145
},
130
146
handleMove (e ) {
131
147
this .maskX = this .outXCheck (e .pageX - this .imgRect .left );
137
153
this .zoomPosition .y = this .maskY * (this .zoomImgHeight / this .imgRect .height )
138
154
},
139
155
handleOut () {
140
- this .zoomShow = false ;
156
+ if (this .delayOut === 0 ) {
157
+ this .zoomShow = false ;
158
+ }else {
159
+ setTimeout (() => {
160
+ this .zoomShow = false ;
161
+ }, this .delayOut );
162
+ }
141
163
},
142
164
outXCheck (x ) {
143
165
x = x - this .maskRect .width / 2 ;
You can’t perform that action at this time.
0 commit comments