mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
1.5 KiB
87 lines
1.5 KiB
6 years ago
|
<script>
|
||
|
const layers = [0, 1, 2, 3, 4, 5, 6, 7, 8];
|
||
|
|
||
|
let y;
|
||
|
</script>
|
||
|
|
||
2 years ago
|
<svelte:window />
|
||
6 years ago
|
|
||
|
<a class="parallax-container" href="https://www.firewatchgame.com">
|
||
5 years ago
|
{#each layers as layer}
|
||
6 years ago
|
<img
|
||
2 years ago
|
style="transform: translate(0,{(-y * layer) / (layers.length - 1)}px)"
|
||
6 years ago
|
src="https://www.firewatchgame.com/images/parallax/parallax{layer}.png"
|
||
|
alt="parallax layer {layer}"
|
||
2 years ago
|
/>
|
||
6 years ago
|
{/each}
|
||
|
</a>
|
||
|
|
||
|
<div class="text">
|
||
2 years ago
|
<span style="opacity: {1 - Math.max(0, y / 40)}"> scroll down </span>
|
||
6 years ago
|
|
||
|
<div class="foreground">
|
||
|
You have scrolled {y} pixels
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<style>
|
||
|
.parallax-container {
|
||
|
position: fixed;
|
||
|
width: 2400px;
|
||
|
height: 712px;
|
||
|
left: 50%;
|
||
2 years ago
|
transform: translate(-50%, 0);
|
||
6 years ago
|
}
|
||
|
|
||
|
.parallax-container img {
|
||
|
position: absolute;
|
||
|
top: 0;
|
||
|
left: 0;
|
||
|
width: 100%;
|
||
|
will-change: transform;
|
||
|
}
|
||
|
|
||
|
.parallax-container img:last-child::after {
|
||
|
content: '';
|
||
|
position: absolute;
|
||
|
width: 100%;
|
||
|
height: 100%;
|
||
2 years ago
|
background: rgb(45, 10, 13);
|
||
6 years ago
|
}
|
||
|
|
||
|
.text {
|
||
|
position: relative;
|
||
|
width: 100%;
|
||
|
height: 300vh;
|
||
2 years ago
|
color: rgb(220, 113, 43);
|
||
6 years ago
|
text-align: center;
|
||
|
padding: 4em 0.5em 0.5em 0.5em;
|
||
|
box-sizing: border-box;
|
||
|
pointer-events: none;
|
||
|
}
|
||
|
|
||
|
span {
|
||
|
display: block;
|
||
|
font-size: 1em;
|
||
|
text-transform: uppercase;
|
||
|
will-change: transform, opacity;
|
||
|
}
|
||
|
|
||
|
.foreground {
|
||
|
position: absolute;
|
||
|
top: 711px;
|
||
|
left: 0;
|
||
|
width: 100%;
|
||
|
height: calc(100% - 712px);
|
||
2 years ago
|
background-color: rgb(32, 0, 1);
|
||
6 years ago
|
color: white;
|
||
|
padding: 50vh 0 0 0;
|
||
|
}
|
||
|
|
||
6 years ago
|
:global(body) {
|
||
|
margin: 0;
|
||
|
padding: 0;
|
||
|
background-color: rgb(253, 174, 51);
|
||
|
}
|
||
2 years ago
|
</style>
|