Skip to content

Commit 6a5e76d

Browse files
feat: 新增delay-in,delay-out属性
1 parent d5eb874 commit 6a5e76d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

example/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525
<!-- Add "scoped" attribute to limit CSS to this component only -->
2626
<style scoped>
2727

28-
</style>
28+
</style>

src/components/ImageMagnifier.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,15 @@
4848
maskOpacity: {
4949
default: .5
5050
},
51-
maskClass: {}
51+
maskClass: {},
52+
delayIn: {
53+
type: Number,
54+
default: 0
55+
},
56+
delayOut: {
57+
type: Number,
58+
default: 0
59+
}
5260
},
5361
data() {
5462
return {
@@ -64,7 +72,7 @@
6472
zoomPosition: {
6573
x: 0,
6674
y: 0
67-
}
75+
},
6876
}
6977
},
7078
computed: {
@@ -115,17 +123,25 @@
115123
},
116124
methods: {
117125
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 () {
120137
this.$nextTick(() => {
138+
this.imgRect = this.$refs.img && this.$refs.img.getBoundingClientRect();
121139
this.maskRect = this.$refs.mask && this.$refs.mask.getBoundingClientRect();
122140
123141
//计算大图宽高
124142
this.zoomImgWidth = (this.imgRect.width / this.maskRect.width) * this.zoomWidth;
125143
this.zoomImgHeight = (this.imgRect.height / this.maskRect.height) * this.zoomHeight;
126144
})
127-
128-
129145
},
130146
handleMove(e) {
131147
this.maskX = this.outXCheck(e.pageX - this.imgRect.left);
@@ -137,7 +153,13 @@
137153
this.zoomPosition.y = this.maskY * (this.zoomImgHeight / this.imgRect.height)
138154
},
139155
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+
}
141163
},
142164
outXCheck(x) {
143165
x = x - this.maskRect.width / 2;

0 commit comments

Comments
 (0)