-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
103 lines (92 loc) · 3.59 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
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
$(function() {
var mediumScreen = '1100px';
var smallScreen = '700px';
var header = $('header');
var links = $('header > #links > a');
var scrollHint = $('.scroll-hint');
var headerColor = '51,51,50';
var logo = $('#logo');
var annaIstomina = $('.anna-istomina');
var annaIstominaLink = $('.anna-istomina > a');
function recomputeHeader() {
var top = $(window).scrollTop();
var minHeaderHeight = 100;
var maxHeaderHeight = Math.max($(document).width() / 12, minHeaderHeight);
var offsetBeforeHeaderFx = 50;
var offsetAfterHeaderFx = offsetBeforeHeaderFx * 7;
var isSmallScreen = false;
if (window.matchMedia(`(max-width: ${smallScreen})`).matches) {
isSmallScreen = true;
}
if (top > 0) {
header.addClass('header-with-shadow');
scrollHint.fadeOut();
} else {
header.removeClass('header-with-shadow');
scrollHint.fadeIn();
}
if (top >= offsetBeforeHeaderFx && top < offsetAfterHeaderFx) {
var opacity = (top - offsetBeforeHeaderFx) / (offsetAfterHeaderFx - offsetBeforeHeaderFx);
}
if (isSmallScreen || top >= offsetAfterHeaderFx) {
// Small screen or scrolled to the middle of screen: use final attributes.
header.css('background-color', `rgba(${headerColor}, 1.0)`);
header.css('height', `${minHeaderHeight}px`);
links.css('color', `#ffffff`);
links.css('border-color', `#ffffff`);
annaIstominaLink.css('color', `#ffffff`);
} else {
if (top < offsetBeforeHeaderFx) {
// Top of the page: use translucent header style.
header.css('height', `${maxHeaderHeight}px`);
header.css('background-color', '');
links.css('color', '');
links.css('border-color', '');
annaIstominaLink.css('color', ``);
} else {
var tween = (top - offsetBeforeHeaderFx) / (offsetAfterHeaderFx - offsetBeforeHeaderFx);
var colorStrength = (255 * tween) | 0;
header.css('height', `${tween * minHeaderHeight + (1.0 - tween) * maxHeaderHeight}px`);
header.css('background-color', `rgba(${headerColor}, ${tween})`);
links.css('color', `rgb(${colorStrength}, ${colorStrength}, ${colorStrength})`);
links.css('border-color', `rgb(${colorStrength}, ${colorStrength}, ${colorStrength})`);
annaIstominaLink.css('color', `rgb(${colorStrength}, ${colorStrength}, ${colorStrength})`);
}
}
if (top < offsetBeforeHeaderFx) {
logo.css('opacity', `0`);
annaIstomina.css('opacity', '1.0');
annaIstomina.css('margin-left', `0`);
} else if (top >= offsetBeforeHeaderFx && top < offsetAfterHeaderFx) {
var tween = (top - offsetBeforeHeaderFx) / (offsetAfterHeaderFx - offsetBeforeHeaderFx);
logo.css('opacity', `${tween}`);
logo.css('left', `${tween * 40}px`);
if (isSmallScreen) {
annaIstomina.css('opacity', `${1.0 - tween}`);
} else {
annaIstomina.css('opacity', '1.0');
}
annaIstomina.css('margin-left', `${tween * 40}px`);
} else {
logo.css('opacity', `1.0`);
logo.css('left', `40px`);
if (isSmallScreen) {
annaIstomina.css('opacity', '0');
} else {
annaIstomina.css('opacity', '1.0');
}
annaIstomina.css('margin-left', `40px`);
}
}
recomputeHeader();
$(window).scroll(recomputeHeader);
$(window).resize(recomputeHeader);
$('.accordion').accordion({
heightStyle: "content",
collapsible: true,
active: false,
});
});
function scrollToContact() {
$("html, body").animate({ scrollTop: $(document).height() - $('footer').height() - $('header').height() }, 1000);
}