-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel.html
172 lines (160 loc) · 4.82 KB
/
parallel.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html>
<!--
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<meta charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Sahitya|Share+Tech+Mono|Yanone+Kaffeesatz" rel="stylesheet">
<style>
html, body {
height: 100%;
margin: 0;
overflow: hidden;
font-family: "Yanone Kaffeesatz";
color: white;
font-size: 18px;
letter-spacing: 1.5px;
line-height: 1.5em;
}
* {
box-sizing: border-box;
}
h1, h2 {
font-family: "Sahitya";
text-shadow: 0 0 4px white, 3px 3px 1px black;
line-height: 1.2em;
}
h1 {
font-size: 4em;
}
h2 {
font-size: 2.5em;
}
code, pre {
font-family: "Share Tech Mono";
font-size: 0.8em;
}
.scene {
height: 150vh;
padding: 5vh 10vw;
}
.parallax {
background-size: cover;
box-sizing: border-box;
width: 100%;
height: 130vh;
/* Since the parallax elements still consume space, we set the margin to undo
the height of this parallax element making it essentially consume 0 space.
*/
margin-bottom: -130vh;
}
.header {
height: 70vh;
}
.parallax.header {
margin-bottom: -70vh;
}
p {
color: white;
margin: 1em 0;
z-index: 1;
position: relative;
}
.viewport {
height: 100%;
overflow-x: hidden;
overflow-y: auto;
position: relative;
-webkit-overflow-scrolling: touch;
}
.woods:not(.header),
.sunset:not(.header) {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.sunset:not(.header) {
align-items: flex-end;
}
.solid {
z-index: 1;
position: relative;
height: 70vh;
font-size: 1.5em;
line-height: 1.5em;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
}
.solid.star {
background-image: linear-gradient(hsla(240, 90%, 8%, 1) 0%, 99%, hsla(217,24%,71%,0) 100%);
box-shadow: -10px -10px 20px hsl(240, 90%, 8%);
}
.solid.woods {
background-color: hsl(195, 16%, 49%);
box-shadow: -10px -10px 20px hsl(195, 16%, 49%);
}
a, a:link, a:active, a:hover, a:visited {
color: hsl(240, 100%, 90%);
display: flex;
align-items: flex-end;
}
</style>
<script src="src/parallax.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
initializeParallax(document.querySelector('.viewport'));
});
</script>
</head>
<body>
<div class="viewport">
<div>
<!-- Specifying a parallax rate of 0.3 will slide the image at that proportion of the scroll speed. -->
<div class="parallax header" style="background-image: url('assets/game_scene1.png');" parallax="0.3"></div>
<div class="scene header">
<img src="assets/front_scene.png">
</div>
<div class="scene solid star">
<p>
What’s this? This is a parallax scroller. But not just yet another parallax scroller, it’s one that doesn’t rely on JavaScript for the animation, that works on both desktop and mobile and has 60fps while scrolling. This was a lot harder than we originally anticipated, so we wrote up what we did for you to read!
</p>
<p>
<a href="https://developers.google.com/web/updates/2016/12/performant-parallaxing">
<img src="assets/game_scene2.png" style="width: 10vw; float: left; margin-right: 2vw;">
Read the article on developers.google.com!</a>
</p>
</div>
<!-- When a rate isn't specified, it will be calculated such that the image always fills the space between the
element before it and the next element with the "parallax-cover" attribute. -->
<div class="parallax" style="background-image: url('assets/MultiCanvas_4.png');" parallax></div>
<div class="scene woods">
<h1>Gazing into the sea 🐳</h1>
<h2>Some people don’t have <code>class</code></h2>
</div>
<div class="scene solid woods" parallax-cover>
<h4>Hello, Multi Layer</h4>
</div>
<!-- When a rate isn't specified and there is no subsequent element with the "parallax-cover" attribute the rate
will be calculated such that the image slides until the end of the scrollable content. -->
<div class="parallax" style="background-image: url('assets/front_scene.png');" parallax></div>
<div class="scene sunset">
<h1>Gazing into the sunset 🌞</h1>
<h2><code>!important</code> is not a performance primitive</h2>
</div>
</div>
</div>
</body>
</html>