Skip to content

Parallax Effect #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: v-1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Total-Parallax/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Parallax Effect</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>

<div class='main'>
<div class="layer l1">Faster</div>
<div class="layer l2">No Effect</div>
<div class="layer l3">Slower</div>
<div class="layer l4">Right</div>
<div class="layer l5">Left</div>
</div>

<script src="script.js"></script>
</body>
</html>
14 changes: 14 additions & 0 deletions Total-Parallax/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function parallax(layer, distance, speed){
const item = document.querySelector(layer);
item.style.transform = "translateY("+ -distance*speed + "px)";
}
function hrparallax(layer, distance, speed){
const item = document.querySelector(layer);
item.style.transform = "translateX("+ -distance*speed + "px)";
}
document.addEventListener('scroll', function() {
parallax('.l1', window.scrollY, 0.5);
parallax('.l3', window.scrollY, -0.5);
hrparallax('.l4', window.scrollY, -0.5);
hrparallax('.l5', window.scrollY, 0.5);
});
41 changes: 41 additions & 0 deletions Total-Parallax/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-size: 24px;
font-family: sans-serif;

}
body{
min-height: 200vh;
min-width: 200vw;
overflow-x: auto;
}
.main{
height: 100vh;
width: 100vw;
display: flex;
justify-content: space-around;
align-items: center;
}
.layer{
width: 15vw;
height: 15vw;
color: #ffffff;
display: flex;
justify-content: center;
align-items: center;
border: 2px solid #FFFFFF;
border-radius: 50%;
background-color: rgb(81, 16, 119);
}

@media only screen and (max-width: 768px){
*{
font-size: 17px;
}
.layer{
width: 18vw;
height: 18vw;
}
}