-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparallax.html
More file actions
143 lines (138 loc) · 5.93 KB
/
parallax.html
File metadata and controls
143 lines (138 loc) · 5.93 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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<title>iiif Perspective Viewer</title>
<style type="text/css">
html, body { height:100%; margin:0; }
body { background:#000; font:14px/1 helvetica,arial,freesans,sans-serif; }
.parallaxer { height:100%; width:100%; overflow:hidden; position:relative; left:0; top:0; user-select:none; }
.parallaxer img { max-height:100%; max-width:100%; margin:auto; position:absolute; left:0; top:0; bottom:0; right:0; }
</style>
</head>
<body>
<!--
<img alt="" src="img/parallax/layer2.1.jpg"><img alt="" src="img/parallax/layer2.2.png"><img alt="" src="img/parallax/layer2.3.png"><img alt="" src="img/parallax/layer2.2.png"><img alt="" src="img/parallax/layer2.3.png">
<img alt="" src="img/parallax/an_artists_studio_01.png"><img alt="" src="img/parallax/an_artists_studio_02.png"><img alt="" src="img/parallax/an_artists_studio_03.png"><img alt="" src="img/parallax/an_artists_studio_04.png"><img alt="" src="img/parallax/an_artists_studio_05.png"><img alt="" src="img/parallax/an_artists_studio_06.png">
-->
<div class="parallaxer js-parallaxer">
<img alt="" src="img/parallax/small/a_printers_workshop_01.png"><img alt="" src="img/parallax/small/a_printers_workshop_02.png"><img alt="" src="img/parallax/small/a_printers_workshop_03.png"><img alt="" src="img/parallax/small/a_printers_workshop_04.png"><img alt="" src="img/parallax/small/a_printers_workshop_05.png"><img alt="" src="img/parallax/small/a_printers_workshop_06.png">
<!--
<img alt="" src="img/parallax/Gestetner_01.png">
<img alt="" src="img/parallax/Gestetner_02.png">
<img alt="" src="img/parallax/Gestetner_03.png">
<img alt="" src="img/parallax/Gestetner_04.png">
<img alt="" src="img/parallax/Gestetner_05.png">
-->
<!--
<img alt="" src="img/parallax/Gestetner_06.png">
-->
</div>
<script src="img/manifesto.bundle.js"></script>
<script type="text/javascript">
function getComputed(el,style){ if(window.getComputedStyle){ var y=document.defaultView.getComputedStyle(el,null).getPropertyValue(style); }else if(el.currentStyle){ if( style=='width' ){ y=el.getBoundingClientRect().right-el.getBoundingClientRect().left }else if( style=='height' ){ y=el.getBoundingClientRect().bottom-el.getBoundingClientRect().top }else{ var y=el.currentStyle[style] } } return parseFloat(y); }
function getEventXY (e) {
const xy = [];
if (e.touches && e.touches.length) {
if (e.touches.length > 1) {
xy[0] = (e.touches[0].pageX + e.touches[0].pageX) / 2;
xy[1] = (e.touches[0].pageY + e.touches[0].pageY) / 2;
} else {
xy[0] = e.touches[0].pageX;
xy[1] = e.touches[0].pageY;
}
} else {
xy[0] = e.pageX;
xy[1] = e.pageY;
}
return xy;
}
const parallaxer = document.querySelector(".js-parallaxer");
const painter = {
id: 1,
size: (el) => {
el.wh = [parseInt(getComputed(el,'width')), Math.ceil(getComputed(el,'height'))];
el.xy = [parseInt(getComputed(el,'left')), Math.ceil(getComputed(el,'top'))];
},
init: (el) => {
el.imgs = el.getElementsByTagName('img');
el.scale = 1;
el.xlate = [0, 0];
el.pinchDelta = 0;
if (!el.paint) {
el.id = el.id || 'parallaxer' + painter.id++;
el.css = el.parentNode.insertBefore(document.createElement('style'), el);
el.paint = () => {
let css = '';
let scalePlus = 0;
if (el.scale > 6) { scalePlus = (el.scale - 6) / 30; }
for (let i = 0; i <= el.imgs.length; i++) {
css += `#${el.id} :nth-child(${i}){ transform: scale(${.5 + (el.scale * i * i / 100) + scalePlus}) translate(${-el.xlate[0] * i * i}% , ${-el.xlate[1] * i * i}%); filter:blur(${i * i * el.scale / 300}px) }`;
}
window.requestAnimationFrame(() => { el.css.innerHTML = css });
};
el.move = (xy) => {
el.xlate = xy;
};
el.zoom = (z) => {
el.scale += z;
if (el.scale < 1) {
el.scale = 1;
}
else if (el.scale > 10) {
el.scale = 10;
}
};
el.paint();
el.onmousemove = painter.touch.bind(null, el);
el.onwheel = painter.touch.bind(null, el);
el.ontouchmove = painter.touch.bind(null, el);
}
},
touch: (el, e) => {
const xyE = getEventXY(e);
if (!el.w) { painter.size(el); }
if (e.type === 'wheel'){
el.zoom(e.deltaY > 0 ? -1 : 1);
} else {
if (e.touches && e.touches.length === 2) {
const pinchDeltaPrevious = el.pinchDelta;
el.pinchDelta = Math.sqrt(Math.pow(e.touches[0].pageX - e.touches[1].pageX, 2) + Math.pow(e.touches[0].pageY - e.touches[1].pageY, 2));
if (pinchDeltaPrevious) {
el.zoom((el.pinchDelta - pinchDeltaPrevious) / 300);
}
} else {
el.move([(xyE[0] - (el.xy[0] + (el.wh[0] / 2))) / el.wh[0], (xyE[1] - (el.xy[1] + (el.wh[1] / 2))) / el.wh[1]]);
}
}
el.paint();
}
};
const qstr = new Map(location.search.slice(1).split('&').map(kv => kv.split('=')));
if (!qstr.has('manifest')) {
console.log('try ?manifest=img/parallax/manifest_peepshow.p3.json');
painter.init(parallaxer);
} else {
parallaxer.innerHTML = '';
manifesto.loadManifest(qstr.get('manifest')).then((manifest) => {
const m = manifesto.create(manifest);
const cvs = m.getSequences()[0].getCanvases();
Array.from(cvs.reverse(), (cv) => {
const im = parallaxer.appendChild(document.createElement('img'));
if (cv.getImages().length) {
// P2 manifest
im.src = `${cv.getImages()[0].getResource().id.replace(/full\/full/, 'full/1200,')}.png`;
} else if (cv.getContent().length) {
// P3 manifest
im.src = `${cv.getContent()[0].getBody()[0].id.replace(/full\/full/, 'full/1200,')}.png`;
}
painter.init(parallaxer);
});
});
}
</script>
</body>
</html>