Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en" >
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Checklist animation</title>
- <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Varela+Round&display=swap'>
- <style>
- html *{
- font-size: 35px !important;
- margin: 2px;
- }
- @media only screen and (min-width: 600px) {
- body {
- margin-right:200px;
- margin-left:200px;
- margin-top: 0;
- }
- }
- .flex{
- display: grid;
- grid-row-gap: 1rem;
- grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
- }
- input, button {
- font-size: 32px;
- width: 80%;
- }
- #checklist {
- --background: #ffffff;
- --text: #414856;
- --check: #4F29F0;
- --disabled: #C3C8DE;
- --width: 70%;
- --border-radius: 10px;
- background: var(--background);
- width: var(--width);
- border-radius: var(--border-radius);
- position: relative;
- box-shadow: 0 10px 30px rgba(65, 72, 86, 0.05);
- padding: 30px 45px;
- display: grid;
- grid-template-columns: 30px auto;
- align-items: center;
- }
- #checklist label {
- color: var(--text);
- position: relative;
- cursor: pointer;
- display: grid;
- align-items: center;
- width: -webkit-fit-content;
- width: -moz-fit-content;
- width: fit-content;
- transition: color 0.3s ease;
- }
- #checklist label::before, #checklist label::after {
- content: "";
- position: absolute;
- }
- #checklist label::before {
- height: 2px;
- width: 8px;
- left: -27px;
- background: var(--check);
- border-radius: 2px;
- transition: background 0.3s ease;
- }
- #checklist label:after {
- height: 4px;
- width: 4px;
- top: 8px;
- left: -25px;
- border-radius: 50%;
- }
- #checklist input[type=checkbox] {
- -webkit-appearance: none;
- -moz-appearance: none;
- position: relative;
- height: 15px;
- width: 15px;
- outline: none;
- border: 0;
- margin: 0 15px 0 0;
- cursor: pointer;
- background: var(--background);
- display: grid;
- align-items: center;
- }
- #checklist input[type=checkbox]::before, #checklist input[type=checkbox]::after {
- content: "";
- position: absolute;
- height: 2px;
- top: auto;
- background: var(--check);
- border-radius: 2px;
- }
- #checklist input[type=checkbox]::before {
- width: 0px;
- right: 60%;
- transform-origin: right bottom;
- }
- #checklist input[type=checkbox]::after {
- width: 0px;
- left: 40%;
- transform-origin: left bottom;
- }
- #checklist input[type=checkbox]:checked::before {
- -webkit-animation: check-01 0.4s ease forwards;
- animation: check-01 0.4s ease forwards;
- }
- #checklist input[type=checkbox]:checked::after {
- -webkit-animation: check-02 0.4s ease forwards;
- animation: check-02 0.4s ease forwards;
- }
- #checklist input[type=checkbox]:checked + label {
- color: var(--disabled);
- -webkit-animation: move 0.3s ease 0.1s forwards;
- animation: move 0.3s ease 0.1s forwards;
- }
- #checklist input[type=checkbox]:checked + label::before {
- background: var(--disabled);
- -webkit-animation: slice 0.4s ease forwards;
- animation: slice 0.4s ease forwards;
- }
- #checklist input[type=checkbox]:checked + label::after {
- -webkit-animation: firework 0.5s ease forwards 0.1s;
- animation: firework 0.5s ease forwards 0.1s;
- }
- @-webkit-keyframes move {
- 50% {
- padding-left: 8px;
- padding-right: 0px;
- }
- 100% {
- padding-right: 4px;
- }
- }
- @keyframes move {
- 50% {
- padding-left: 8px;
- padding-right: 0px;
- }
- 100% {
- padding-right: 4px;
- }
- }
- @-webkit-keyframes slice {
- 60% {
- width: 100%;
- left: 4px;
- }
- 100% {
- width: 100%;
- left: -2px;
- padding-left: 0;
- }
- }
- @keyframes slice {
- 60% {
- width: 100%;
- left: 4px;
- }
- 100% {
- width: 100%;
- left: -2px;
- padding-left: 0;
- }
- }
- @-webkit-keyframes check-01 {
- 0% {
- width: 4px;
- top: auto;
- transform: rotate(0);
- }
- 50% {
- width: 0px;
- top: auto;
- transform: rotate(0);
- }
- 51% {
- width: 0px;
- top: 8px;
- transform: rotate(45deg);
- }
- 100% {
- width: 5px;
- top: 8px;
- transform: rotate(45deg);
- }
- }
- @keyframes check-01 {
- 0% {
- width: 4px;
- top: auto;
- transform: rotate(0);
- }
- 50% {
- width: 0px;
- top: auto;
- transform: rotate(0);
- }
- 51% {
- width: 0px;
- top: 8px;
- transform: rotate(45deg);
- }
- 100% {
- width: 5px;
- top: 8px;
- transform: rotate(45deg);
- }
- }
- @-webkit-keyframes check-02 {
- 0% {
- width: 4px;
- top: auto;
- transform: rotate(0);
- }
- 50% {
- width: 0px;
- top: auto;
- transform: rotate(0);
- }
- 51% {
- width: 0px;
- top: 8px;
- transform: rotate(-45deg);
- }
- 100% {
- width: 10px;
- top: 8px;
- transform: rotate(-45deg);
- }
- }
- @keyframes check-02 {
- 0% {
- width: 4px;
- top: auto;
- transform: rotate(0);
- }
- 50% {
- width: 0px;
- top: auto;
- transform: rotate(0);
- }
- 51% {
- width: 0px;
- top: 8px;
- transform: rotate(-45deg);
- }
- 100% {
- width: 10px;
- top: 8px;
- transform: rotate(-45deg);
- }
- }
- @-webkit-keyframes firework {
- 0% {
- opacity: 1;
- box-shadow: 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0;
- }
- 30% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- box-shadow: 0 -15px 0 0px #4F29F0, 14px -8px 0 0px #4F29F0, 14px 8px 0 0px #4F29F0, 0 15px 0 0px #4F29F0, -14px 8px 0 0px #4F29F0, -14px -8px 0 0px #4F29F0;
- }
- }
- @keyframes firework {
- 0% {
- opacity: 1;
- box-shadow: 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0, 0 0 0 -2px #4F29F0;
- }
- 30% {
- opacity: 1;
- }
- 100% {
- opacity: 0;
- box-shadow: 0 -15px 0 0px #4F29F0, 14px -8px 0 0px #4F29F0, 14px 8px 0 0px #4F29F0, 0 15px 0 0px #4F29F0, -14px 8px 0 0px #4F29F0, -14px -8px 0 0px #4F29F0;
- }
- }
- body {
- background: #E8EBF3;
- height: 100vh;
- font: 400 32px "Varela Round", sans-serif;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- }
- body .socials {
- position: fixed;
- display: block;
- left: 20px;
- bottom: 20px;
- }
- body .socials > a {
- display: block;
- width: 30px;
- opacity: 0.2;
- transform: scale(var(--scale, 0.8));
- transition: transform 0.3s cubic-bezier(0.38, -0.12, 0.24, 1.91);
- }
- body .socials > a:hover {
- --scale: 1;
- }
- </style>
- </head>
- <body>
- <input id="input" type="text" placeholder="Enter List Sperated by Commas">
- <button onclick="add_items()">Add Items</button>
- <!-- partial:index.partial.html -->
- <div id="checklist">
- </div>
- <button onclick="submit()" onchange="submit()">Submit</button>
- </body>
- <script>
- add_item_on_enter();
- function add_items(){
- var list = document.getElementById("checklist");
- var input = document.getElementById("input");
- var items = input.value.split(",");
- input.value = "";
- for(i of items){
- var elementExists = document.getElementById(i);
- if( !elementExists ){
- var id = (Math.random() + 1).toString(36).substring(2);
- list.innerHTML += `
- <input id="${i}" class="items" type="checkbox" name="r" value="${i}">
- <label for="${i}">${i}</label>
- `;
- }
- }
- }
- function submit(){
- var items = document.querySelectorAll(".items");
- var submit_string = "";
- for ( i of items ){
- var checked = i.checked;
- var item = i.value;
- submit_string += `${item}:${checked}|`
- }
- console.log(submit_string);
- }
- function add_item_on_enter(){
- // Get the input field
- var input = document.getElementById("input");
- // Execute a function when the user presses a key on the keyboard
- input.addEventListener("keypress", function(event) {
- // If the user presses the "Enter" key on the keyboard
- if (event.key === "Enter") {
- // Cancel the default action, if needed
- event.preventDefault();
- // Trigger the button element with a click
- add_items();
- }
- });
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement