File tree Expand file tree Collapse file tree 3 files changed +29
-38
lines changed Expand file tree Collapse file tree 3 files changed +29
-38
lines changed Original file line number Diff line number Diff line change 1
1
# vue-image-magnifier
2
2
3
- ## Project setup
3
+ ## setup
4
4
```
5
- npm install
5
+ npm install vue-image-magnifier
6
6
```
7
7
8
- ### Compiles and hot-reloads for development
8
+ ### use
9
9
```
10
- npm run serve
10
+ import ImageMagnifier from vue-image-magnifier
11
+ Vue.use(ImageMagnifier)
12
+ //or
13
+ import {ImageMagnifier} from vue-image-magnifier
11
14
```
12
15
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
26
17
```
18
+ npm run demo
19
+ ```
Original file line number Diff line number Diff line change 1
1
<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 >
3
8
</template >
4
9
5
10
<script >
Original file line number Diff line number Diff line change 1
1
<template >
2
- <div class =" image-magnifier" >
2
+ <div class =" image-magnifier" :style = " style " >
3
3
<img :width =" width"
4
4
:height =" height"
5
5
:src =" src"
9
9
@mouseout =" handleOut"
10
10
ref =" img"
11
11
/>
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" >
13
13
</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" >
15
15
<img :src =" zoomSrc" :style =" zoomImgStyle" />
16
16
</div >
17
17
</div >
68
68
}
69
69
},
70
70
computed: {
71
+ style () {
72
+ return {
73
+ position: ' relative' ,
74
+ cursor: ' move'
75
+ }
76
+ },
71
77
maskStyle () {
72
78
return {
73
79
position: ' absolute' ,
109
115
this .imgRect = this .$refs .img && this .$refs .img .getBoundingClientRect ();
110
116
this .$nextTick (() => {
111
117
this .maskRect = this .$refs .mask && this .$refs .mask .getBoundingClientRect ();
118
+
119
+ // 计算大图宽高
112
120
this .zoomImgWidth = (this .imgRect .width / this .maskRect .width ) * this .zoomWidth ;
113
121
this .zoomImgHeight = (this .imgRect .height / this .maskRect .height ) * this .zoomHeight ;
114
122
})
119
127
this .maskX = this .outXCheck (e .pageX - this .imgRect .left );
120
128
this .maskY = this .outYCheck (e .pageY - this .imgRect .top );
121
129
this .zoomLeft = this .imgRect .width + 10 ;
130
+
131
+ // 计算大图偏移量
122
132
this .zoomPosition .x = this .maskX * (this .zoomImgWidth / this .imgRect .width )
123
133
this .zoomPosition .y = this .maskY * (this .zoomImgHeight / this .imgRect .height )
124
134
},
148
158
}
149
159
}
150
160
</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 >
You can’t perform that action at this time.
0 commit comments