-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
72 lines (64 loc) · 2.1 KB
/
main.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
72
jQuery(document).ready(function ($) {
//cache some jQuery objects
var modalTrigger = $('.cd-modal-trigger'),
transitionLayer = $('.cd-transition-layer'),
transitionBackground = transitionLayer.children(),
modalWindow = $('.cd-modal');
var frameProportion = 1.78, //png frame aspect ratio
frames = transitionLayer.data('frame'), //number of png frames
resize = false;
//set transitionBackground dimentions
setLayerDimensions();
$(window).on('resize', function () {
if (!resize) {
resize = true;
!window.requestAnimationFrame
? setTimeout(setLayerDimensions, 300)
: window.requestAnimationFrame(setLayerDimensions);
}
});
//open modal window
modalTrigger.on('click', function (event) {
event.preventDefault();
var modalId = $('.cd-modal');
transitionLayer.addClass('visible opening');
var delay = $('.no-cssanimations').length > 0 ? 0 : 800;
setTimeout(function () {
modalWindow.filter(modalId).addClass('visible');
transitionLayer.removeClass('opening');
}, delay);
});
//close modal window
modalWindow.on('click', '.modal-close', function (event) {
event.preventDefault();
transitionLayer.addClass('closing');
modalWindow.removeClass('visible');
transitionBackground.one(
'webkitAnimationEnd oanimationend msAnimationEnd animationend',
function () {
transitionLayer.removeClass('closing opening visible');
transitionBackground.off(
'webkitAnimationEnd oanimationend msAnimationEnd animationend'
);
}
);
});
function setLayerDimensions() {
var windowWidth = $(window).width(),
windowHeight = $(window).height(),
layerHeight,
layerWidth;
if (windowWidth / windowHeight > frameProportion) {
layerWidth = windowWidth;
layerHeight = layerWidth / frameProportion;
} else {
layerHeight = windowHeight * 1.2;
layerWidth = layerHeight * frameProportion;
}
transitionBackground.css({
width: layerWidth * frames + 'px',
height: layerHeight + 'px',
});
resize = false;
}
});