Skip to content

Rolling button animation #4

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

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rolling Button</title>
<link rel="stylesheet" href="styles/style.css">
</head>
<body>
<div class="container">
<div class="toggle">
<input type="checkbox" class="toggle-1">
<span class="circle"></span>
</div>
</div>
</body>
</html>
74 changes: 74 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
*,
:before,
:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #e0e0e0;
}

.toggle {
width: 150px;
height: 50px;
position: relative;
}

input[type=checkbox] {
position: absolute;
width: 100%;
height: 100%;
border-radius: 30px;
box-shadow: 10px 10px 20px 0 rgba(0, 0, 0, 0.2), -10px -10px 20px 0 rgba(255, 255, 255, 0.5);
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
cursor: pointer;
transition: all 500ms ease-in-out;
outline: none;
}

.circle {
position: absolute;
width: 45px;
height: 45px;
top: 50%;
left: 5px;
transform: translateY(-50%);
border-radius: 50%;
background-color: #fff;
box-shadow: 1px 1px 10px 0 dodgerblue inset, -5px -5px 20px 0 dodgerblue inset;
transition: all 750ms ease-in-out;
pointer-events: none;
}

.circle:before {
content: "ON";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: monospace;
font-size: 1.15rem;
}

.toggle-1:checked {
box-shadow: inset 6px 6px 10px 0 rgba(0, 0, 0, 0.2), inset -6px -6px 10px 0 rgba(255, 255, 255, 0.5);
}

.toggle-1:checked ~ .circle {
box-shadow: 1px 1px 10px 0 rebeccapurple inset, -5px -5px 20px 0 rebeccapurple inset;
background-color: #fff;
left: 100px;
transform: translateY(-50%) rotate(360deg);
}

.toggle-1:checked ~ .circle:before {
content: "OFF";
}/*# sourceMappingURL=style.css.map */
1 change: 1 addition & 0 deletions styles/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions styles/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
*,
:before,
:after {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #e0e0e0;
}

.toggle {
width: 150px;
height: 50px;
position: relative;
}

input[type="checkbox"] {
position: absolute;
width: 100%;
height: 100%;
border-radius: 30px;
box-shadow: 10px 10px 20px 0 rgba(0, 0, 0, 0.2),
-10px -10px 20px 0 rgba(255, 255, 255, 0.5);
appearance: none;
cursor: pointer;
transition: all 500ms ease-in-out;
outline: none;
}

.circle {
position: absolute;
width: 45px;
height: 45px;
top: 50%;
left: 5px;
transform: translateY(-50%);
border-radius: 50%;
background-color: #fff;
box-shadow: 1px 1px 10px 0 dodgerblue inset, -5px -5px 20px 0 dodgerblue inset;
transition: all 750ms ease-in-out;
pointer-events: none;
}

.circle:before {
content: "ON";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-family: monospace;
font-size: 1.15rem;
}

.toggle-1:checked {
box-shadow: inset 6px 6px 10px 0 rgba(0, 0, 0, 0.2),
inset -6px -6px 10px 0 rgba(255, 255, 255, 0.5);
}

.toggle-1:checked ~ .circle {
box-shadow: 1px 1px 10px 0 rebeccapurple inset, -5px -5px 20px 0 rebeccapurple inset;
background-color: #fff;
left: 100px;
transform: translateY(-50%) rotate(360deg);
}

.toggle-1:checked ~ .circle:before {
content: "OFF";
}