-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.js
executable file
·42 lines (39 loc) · 1.29 KB
/
default.js
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
var url = 'http://upload.wikimedia.org/wikipedia/commons/9/9f/Lichtenstein_360_degree_panorama_%28aka%29.jpg';
function loadimg() {
var pos = 0;
var img = new Image();
img.src = url;
img.onload = function() {
var img1 = document.createElement('div');
img1.className = 'pan';
img1.id = 'imgx';
img1.style.backgroundImage = "url("+url+")";
document.body.appendChild(img1);
window.onkeydown = function(e) {
e = e || window.event;
switch(e.keyCode) {
case 37:
pos+=100;
break;
case 39:
pos-=100;
break;
}
var extreme=Math.round(img.width / (img.height / document.body.clientHeight));
/* // I prefer this as it keeps pos relatively low.
* // It doesn't look as nice with CSS transitions.
*
* if (pos >= extreme) {
* pos -= extreme;
* }
* else if (pos <= -(extreme)) {
* pos += extreme;
* }
*/
var imgx=document.getElementById('imgx');
imgx.style.backgroundPositionX = pos+'px';
};
};
return img;
}
var img = loadimg();