Вот мой код.
HTML:
Код: Выделить всё
Parallax Scrolling Website | Vanilla Javascript
[*]
[url=#]Logo[/url]
[list]
[url=#]Home[/url]
[*][url=#]About[/url]
[*][url=#]Work[/url]
[*][url=#]Sources[/url]
[/list]
[img]Background (1).png[/img]
[img]Back Mountains.png[/img]
[img]Front Mountains.png[/img]
[img]Moon.png[/img]
[img]Ocean.png[/img]
Moon Light
[url=#sec]Explore[/url]
[img]Weird land_.png[/img]
Parallax Scrolling Effects
Something Something Something
Something Something Something
let Background = document.getElementById('background');
let Back_mountains = document.getElementById('back_mountains');
let Front_mountains = document.getElementId('front_mountains');
let Moon = document.getElementById('moon');
let Ocean = document.getElementById('ocean');
let Text = document.getElementById('text');
let Btn = document.getElementById('btn');
let Weird_land = document.getElementById('weird_land');
window.addEventListener('scroll', function(){
let value = window.scrollY;
moon.style.left = value * 1.05 + 'px';
back_mountains.style.top = value * -1.25 + 'px';
front_mountains.style.top = value * .5 + 'px';
text.style.marginTop = value * 2 + 'px';
})
Код: Выделить всё
@import url('https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700,800,900&display=swap');
*
{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
scroll-behavior: smooth;
}
body
{
min-height: 100vh;
overflow-x: hidden;
background: linear-gradient(#01789c, #1c0130);
}
header
{
position: absolute;
top: 0;
left: 0;
width: 100%;
padding: 30px 100px;
display: flex;
justify-content: space-between;
align-items: center;
z-index: 10000;
}
header .logo
{
color: #fff;
font-weight: 700;
text-decoration: none;
font-size: 2em;
text-transform: uppercase;
letter-spacing: 2px;
}
header ul
{
display: flex;
justify-content: center;
align-items: center;
}
header ul li
{
list-style: none;
margin-left: 20px;
}
header ul li a
{
text-decoration: none;
padding: 6px 15px;
color: #fff;
border-radius: 20px
}
header ul li a:hover, header ul li a.active
{
background: #fff;
color: #2b1055;
}
section
{
position: relative;
width: 100%;
height: 100vh;
padding: 100px;
display: flex;
justify-content: center;
align-items: center;
}
section::before
{
content: '';
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background: linear-gradient(to top, #1c0522, transparent);
z-index: 1000;
}
section img
{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: none;
}
section img#moon
{
mix-blend-mode: screen;
}
section img#mountains_front
{
z-index: 10;
}
#text
{
position: absolute;
color: #fff;
white-space: nowrap;
font-size: 7.5vw;
z-index: 9;
}
#btn
{
text-decoration: none;
display: inline-block;
padding: 8px 30px;
border-radius: 40px;
background: #fff;
color: #2b1055;
font-size: 1.5em;
z-index: 9;
transform: translateY(100px);
}
.sec
{
position: relative;
padding: 100px;
background: #1c0522;
}
.sec h2
{
font-size: 3.5em;
margin-bottom: 10px;
color: #fff;
}
.sec p
{
font-size: 1.2em;
color: #fff;
}
Подробнее здесь: https://stackoverflow.com/questions/782 ... f-the-user