-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.12 KB
/
Copy pathindex.js
File metadata and controls
45 lines (37 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var pinchZoom = require('./lib/pinchZoom')
var pinch = {}
pinch.install = function(Vue){
Vue.directive('pinch',{
bind : function(el,binding){
el.onclick = function(){
var _src = el.getAttribute("src")
var img = new Image()
img.src = _src
var option = binding.value ? {maxScale : binding.value} : {}
img.onload = () => {
var cover = document.createElement("div")
cover.setAttribute("id",'cover')
cover.appendChild(img)
var window_width = window.innerWidth;
cover.style.cssText = `width:${window_width}px;
height:100%;
background-color: #000000;
position: fixed;
top:0;
left:0;
overflow: auto;
z-index:999;`
var _body = document.querySelector("body")
_body.appendChild(cover)
// 图片放大
var pinch = new pinchZoom(img,option)
cover.addEventListener("click",(e) => {
pinch.destroy()
_body.removeChild(e.currentTarget);
})
}
}
}
})
}
module.exports = pinch