-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathembed.js
66 lines (57 loc) · 1.74 KB
/
embed.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
(function() {
var sheet = document.getElementById('style').sheet;
function addRule (selector, css) {
var propText = Object.keys(css).map(function(p){
return p+":"+css[p];
}).join(";");
if (sheet.cssRules.length) {
sheet.deleteRule(sheet.cssRules.length - 1);
}
sheet.insertRule(selector + "{" + propText + "}", sheet.cssRules.length);
}
var nbItems = 5;
var pad = 20;
var nav = document.querySelector('.Nav');
var navItems = [].slice.call(document.querySelectorAll('.Nav-item'));
var navAction = document.querySelector('.Nav-action');
var size = nav.offsetWidth;
var ratio = 60 / size;
var ratioInversed = size / 60;
window.addEventListener('resize', resize);
function resize () {
// get actual size (based on viewport)
size = nav.offsetWidth;
// update ratio
ratio = 60 / size;
ratioInversed = size / 60;
// for each item, compute line-height and set font-size
navItems.map(function (item) {
item.style.lineHeight = ((size - 2 * pad) / nbItems) + 'px';
item.style.fontSize = size / 150 + 'em';
});
// for ::after elements, compute top
var top = ratioInversed * 4 - 4;
addRule(".Nav-link::after", {
transform: 'translateY(' + top + 'px) scaleY(' + ratioInversed + ')'
});
updateScales();
}
function updateScales () {
// check if menu is close
if (nav.classList.contains('is-close')) {
nav.style.transform = 'scale(' + ratio + ')';
navAction.style.transform = 'scale(' + size / 30 + ')';
} else {
nav.style.transform = 'scale(1)';
navAction.style.transform = 'scale(1)';
}
}
var action = document.querySelector('.Nav-action');
action.addEventListener('click', toggleNav);
function toggleNav (ev) {
nav.classList.toggle('is-close');
updateScales();
}
updateScales();
resize();
})();