-
Notifications
You must be signed in to change notification settings - Fork 0
/
sudoers-parallax-header.html
123 lines (117 loc) · 3.83 KB
/
sudoers-parallax-header.html
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<link rel="import" href="../polymer/polymer.html">
<dom-module id="sudoers-parallax-header">
<template>
<style>
:host {
position: relative;
display: inline-block;
width: 100%;
height: 300px;
text-align: center;
overflow: hidden;
}
#bg {
position: absolute;
left: 50%;
top: 50%;
width: 1600px;
height: 600px;
margin-left: -800px;
margin-top: -450px;
background-repeat: no-repeat;
@apply (--sudoers-parallax-background);
}
#fg {
position: absolute;
width: 100%;
height: 100px;
top: 50%;
margin: -180px 0 0 0;
color: #fff;
}
h1, h2, h3, h4, h5 {
margin: 0;
padding: 0;
font-size: 6em;
}
@media all and (max-width: 630px) {
h1, h2, h3, h4, h5 {
font-size: 3.5em;
}
}
</style>
<div id="bg">
<content></content>
</div>
<div id="fg">
<h1>[[title]]</h1>
</div>
</template>
</dom-module>
<script>
(function() {
'use strict';
var manager = (function() {
var update, handler, getScrollTop;
var delegates = [];
// Create the getScrollTop method based on the browser type.
if (typeof pageYOffset!='undefined')
getScrollTop = function() { return pageYOffset; };
else {
var de = document.documentElement,
db = document.body;
var obj = (de.clientHeight) ? de : db;
getScrollTop = function() { return obj.scrollTop; };
}
// The `handler` method gets called every time scrolling / resizing occurs.
handler = function() {
var wTop = getScrollTop();
var wBot = wTop+window.innerHeight;
var wHeight = wBot-wTop;
for (var idx in delegates) {
var elem = delegates[idx];
var eTop = elem.offsetTop;
var eBot = eTop + elem.offsetHeight;
if ((eTop >= wTop || eBot >= wTop) && (eTop <= wBot || eBot <= wBot))
update(elem, eTop, eBot, wTop, wHeight);
}
};
// The `update` method updates a single item stored in the `elem`
// scope variable, based on `eTop`, `eBot`, `wHeight` and `val`.
update = function(elem, eTop, eBot, wTop, wHeight) {
var zero = eTop - wHeight;
var val = 1 / (eBot - zero) * (wTop - zero);
elem.fgs.opacity = (val - 0.1) * 2;
elem.fgs.transform = 'translateY(' + (elem.fgAmplitude * val) + 'px)';
elem.bgs.transform = 'translateY(' + (elem.bgAmplitude * val) + 'px)';
};
document.addEventListener('scroll', handler);
window.addEventListener('resize', handler);
return {
register: function(elem) {
if (delegates.indexOf(elem) < 0) {
elem.fgs = elem.$.fg.style;
elem.bgs = elem.$.bg.style;
delegates.push(elem);
handler();
}
},
unregister: function(elem) {
var idx = delegates.indexOf(elem);
if (idx >= 0)
delegates.splice(idx, -1);
}
};
})();
Polymer({
is: 'sudoers-parallax-header',
properties: {
title: String,
bgAmplitude: Number,
fgAmplitude: Number
},
attached: function() { manager.register(this); },
detached: function() { manager.unregister(this); }
});
})();
</script>