-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
71 lines (53 loc) · 2 KB
/
script.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
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
//SENSIBILITÀ VARIAZIONE MOUSE/GYRO
var strength = 0.2;
var parallaxBox = $('#parallax-container');
isMobile = false;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
isMobile = true;
}
function parallaxMove (parallaxContainer, x, y, boxWidth, boxHeight) {
$(parallaxContainer).find('.parallax-layer').each(function() {
var depth = $(this).data('depth');
var moveX = ((boxWidth / 2) - x) * (strength * depth);
var moveY = ((boxHeight / 2) - y) * (strength * depth);
$(this).css({transform: "translate3d(" + moveX + "px, " + moveY + "px, 0)"});
//$(this).removeClass('is-out');
});
}
//COSA FARE SE MOUSE ESCE DA RIQUADRO
function resetParallaxPosition (parallaxContainer) {
$(parallaxContainer).find('.parallax-layer').each(function() {
$(this).css({ transform: "translate3d( 0, 0, 0 )"});
//$(this).addClass('is-out');
});
event.stopPropagation();
}
if(!isMobile) {
parallaxBox.mousemove(function(event) {
event.stopPropagation();
event = event || window.event;
var x = Math.floor(event.clientX - $(this).offset().left),
y = Math.floor(event.clientY - $(this).offset().top),
boxWidth = $(this).width(),
boxHeight = $(this).height();
parallaxMove(this, x, y, boxWidth, boxHeight);
});
parallaxBox.mouseleave(function(event) {
if( !$(event.target).is($(this))) {
resetParallaxPosition(this);
}
});
} else if(isMobile) {
var elem = document.getElementById("view3d");
window.addEventListener("deviceorientation", function(event) {
event.stopPropagation();
event = event || window.event;
var rotatedY = Math.min(Math.max(parseInt(Math.floor(event.gamma)), -45), 45),
rotatedX = Math.min(Math.max(parseInt(Math.floor(event.beta)), -45), 45),
boxWidth = parallaxBox.width(),
boxHeight = parallaxBox.height();
var moveX = ((boxWidth/2) * rotatedY) / 45;
var moveY = ((boxWidth/2) * rotatedX) / 45;
parallaxMove(parallaxBox, moveX, moveY, boxWidth, boxHeight);
});
}