Skip to content

Commit 967fc39

Browse files
docs: update readme
1 parent 15fd75e commit 967fc39

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
# vue-image-magnifier
22

3-
## Project setup
3+
## setup
44
```
5-
npm install
5+
npm install vue-image-magnifier
66
```
77

8-
### Compiles and hot-reloads for development
8+
### use
99
```
10-
npm run serve
10+
import ImageMagnifier from vue-image-magnifier
11+
Vue.use(ImageMagnifier)
12+
//or
13+
import {ImageMagnifier} from vue-image-magnifier
1114
```
1215

13-
### Compiles and minifies for production
14-
```
15-
npm run build
16-
```
17-
18-
### Run your tests
19-
```
20-
npm run test
21-
```
22-
23-
### Lints and fixes files
24-
```
25-
npm run lint
16+
### demo
2617
```
18+
npm run demo
19+
```

example/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<template>
2-
<ImageMagnifier :src="image" :zoom-src="image" width="400" height="300" zoom-width="400" zoom-height="300"></ImageMagnifier>
2+
<ImageMagnifier :src="image"
3+
:zoom-src="image"
4+
width="400"
5+
height="300"
6+
zoom-width="400"
7+
zoom-height="300"></ImageMagnifier>
38
</template>
49

510
<script>

src/components/ImageMagnifier.vue

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div class="image-magnifier">
2+
<div class="image-magnifier" :style="style">
33
<img :width="width"
44
:height="height"
55
:src="src"
@@ -9,9 +9,9 @@
99
@mouseout="handleOut"
1010
ref="img"
1111
/>
12-
<div class="image-magnifier__mask" :style="maskStyle" v-show="zoomShow" ref="mask">
12+
<div class="image-magnifier__mask" :class="maskClass" :style="maskStyle" v-show="zoomShow" ref="mask">
1313
</div>
14-
<div class="image-magnifier__zoom" :style="zoomStyle" v-show="zoomShow">
14+
<div class="image-magnifier__zoom" :class="zoomClass" :style="zoomStyle" v-show="zoomShow">
1515
<img :src="zoomSrc" :style="zoomImgStyle"/>
1616
</div>
1717
</div>
@@ -68,6 +68,12 @@
6868
}
6969
},
7070
computed: {
71+
style() {
72+
return {
73+
position: 'relative',
74+
cursor: 'move'
75+
}
76+
},
7177
maskStyle() {
7278
return {
7379
position: 'absolute',
@@ -109,6 +115,8 @@
109115
this.imgRect = this.$refs.img && this.$refs.img.getBoundingClientRect();
110116
this.$nextTick(() => {
111117
this.maskRect = this.$refs.mask && this.$refs.mask.getBoundingClientRect();
118+
119+
//计算大图宽高
112120
this.zoomImgWidth = (this.imgRect.width / this.maskRect.width) * this.zoomWidth;
113121
this.zoomImgHeight = (this.imgRect.height / this.maskRect.height) * this.zoomHeight;
114122
})
@@ -119,6 +127,8 @@
119127
this.maskX = this.outXCheck(e.pageX - this.imgRect.left);
120128
this.maskY = this.outYCheck(e.pageY - this.imgRect.top);
121129
this.zoomLeft = this.imgRect.width + 10;
130+
131+
//计算大图偏移量
122132
this.zoomPosition.x = this.maskX * (this.zoomImgWidth / this.imgRect.width)
123133
this.zoomPosition.y = this.maskY * (this.zoomImgHeight / this.imgRect.height)
124134
},
@@ -148,20 +158,3 @@
148158
}
149159
}
150160
</script>
151-
152-
<style scoped>
153-
.image-magnifier {
154-
position: relative;
155-
cursor: move;
156-
}
157-
158-
.image-magnifier__img {
159-
160-
}
161-
162-
.image-magnifier__mask {
163-
}
164-
165-
.image-magnifier__zoom {
166-
}
167-
</style>

0 commit comments

Comments
 (0)