-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransform_preview.html
128 lines (124 loc) · 3.25 KB
/
transform_preview.html
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head>
<title>scroll</title>
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<style type="text/css">
body{
margin: 0;
}
#container{
position: relative;
width: 100vw;
height: 100vh;
}
.wrapper{
position: relative;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
width: 100vw;
height: 200px;
}
.preview{
position: relative;
top: 10%;
left: 10%;
width: 200px;
background-color: rgba(0, 0, 0, .5);
}
.pre_border{
position: absolute;
top: 0px;
left: 0px;
z-index: 3;
width: 100%;
box-sizing: border-box;
border: 2px solid red;
transform-origin: 0px 0px 0px;
}
.pre_wrapper{
width: 100%;
}
.content{
z-index: 2;
width: 100%;
height: 100%;
text-align: center;
background-color: #9afbbc;
transform-origin: 0px 0px 0px;
}
</style>
</head>
<body>
<div id="container">
<div class="preview">
<div class="pre_border"></div>
<div class="pre_wrapper">
<div class="content">
preview
</div>
</div>
</div>
<div class="wrapper">
<div class="content">
touch me
</div>
</div>
</div>
<script async type="text/javascript" src="./lib/weScroll.min.js"></script>
<script type="text/javascript">
window.onload = function(){
var $ = function (selector){
return document.querySelector(selector);
}
var wrapper = $(".wrapper");
var target = wrapper.children[0];
function applyStyle(target, style, value){
var prefixStyle = "webkit" + style.charAt(0).toUpperCase() + style.substr(1)
target.style[style] = value
target.style[prefixStyle] = value
}
function createRender(){
var preWrapper = $(".preview")
var preBorder = $(".pre_border")
var thumbScale = 200 / wrapper.offsetWidth
var thumbHeight = wrapper.offsetHeight * thumbScale
var topPercent = ( thumbHeight - preWrapper.children[0].offsetHeight)/ 2 / thumbHeight * 100
let zoomed = false
let lastScale = 1
applyStyle(preBorder, "height", thumbHeight + "px")
applyStyle(preBorder.parentNode, "height", thumbHeight + "px")
applyStyle($('.pre_wrapper'), "height", thumbHeight + "px")
return function(x,y,scale){
var transformStyle = "translate3d(" + x + "px," + y +"px, 0px) scale("+ scale +")";
var preTransformStyle = "translate3d( " + (-x * thumbScale / scale) + "px," + (-y * thumbScale / scale) + "px, 0px) scale( " + ( 1 / scale) + ")"
applyStyle(target, "transform", transformStyle)
applyStyle(preBorder, "transform", preTransformStyle)
if (lastScale !== scale && !zoomed) {
applyStyle(preBorder, "transformOrigin", "0px " + topPercent + "% 0")
zoomed = true
}
lastScale = scale
}
}
var scroller = new WeScroll(wrapper, {
disablePointer: true,
disableTouch: false,
disableMouse: false,
zoom: true,
ease: "quadratic",
zoomMin: 0.5,
startZoom: 1,
zoomMax: 2,
bounceTime: 600,
render: createRender(),
tap: true,
});
wrapper.addEventListener("tap", function(e){
scroller.zoom(1.5);
}, false)
}
</script>
</body>
</html>