<main class="container"> <div class="progress"></div> <div class="counter">1</div> <button class="button">Toggle</button> </main> <script src="https://rawgit.com/lmgonzalves/momentum-slider/master/dist/momentum-slider.min.js"></script> :root { --progress: 100; } *, *:before, *:after { box-sizing: border-box; } body { overflow: hidden; } body:before { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-left: 50vw solid #FBD786; /* Градиент */; border-right: 50vw solid #FBD786; border-top: 50vh solid #C6FFDD; border-bottom: 50vh solid #C6FFDD; z-index: -1; } .container { position: absolute; left: 50%; top: 50%; width: 340px; height: 540px; background-color: #354051; box-shadow: 0 0 100px rgba(0, 0, 0, 0.5); transform: translate(-50%, -50%); overflow: hidden; } .container:before { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 25px; background-color: rgba(0, 0, 0, 0.2); z-index: 3; } .progress { position: absolute; left: 0; top: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; } .progress:before { content: ""; position: absolute; left: calc(50% - 30px); bottom: 50px; width: 60px; height: 60px; background-color: #0c7702; border-radius: 100%; transform: scale(1); transition: 0.8s transform; } .progress:after { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.1); box-shadow: 0 50px 0 50px rgba(0, 0, 0, 0.1); transform: translateY(calc(var(--progress) * 1%)); transition: 0.95s transform cubic-bezier(0.175, 0.885, 0.32, 1.275); } .counter { display: flex; align-items: center; justify-content: center; position: absolute; left: 0; top: 0; width: 100%; height: 100%; font-size: 100px; font-family: "Roboto Mono", monospace; color: #FFFFFF; pointer-events: none; opacity: 0; z-index: 3; transition: 0.5s opacity; } .button { position: absolute; left: calc(50% - 30px); bottom: 50px; width: 60px; height: 60px; padding: 0; color: transparent; background-color: transparent; outline: none; border: none; border-radius: 100%; text-indent: -999px; z-index: 2; cursor: pointer; } .button:before { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-radius: 100%; background-color: transparent; transform: scale(0); transition: 0.5s 0.5s transform, 0.5s 0.5s background-color; } .button:after { content: ""; position: absolute; left: 0; top: 0; width: 100%; height: 100%; border-radius: 100%; opacity: 0; box-shadow: inset 0 0 0 20px white; transition: 0s; pointer-events: none; z-index: -1; } .container--running .progress:before { transform: scale(17); transition: 0.8s transform cubic-bezier(0.6, -0.28, 0.735, 0.045); } .container--running .counter { opacity: 1; transition: 1s opacity; } .container--running .button:before { background-color: #354051; transform: scale(1); transition: 0.5s 0.5s transform, 0.5s 0.5s background-color; } .container--running .button:after { opacity: 1; transform: scale(2.5); box-shadow: inset 0 0 0 0 rgba(255, 255, 255, 0); transition: all 0.8s, opacity 0.3s; } .ms-container { position: relative; top: 50%; width: 340px; max-width: 100%; margin: 0 auto; overflow: hidden; transform: translateY(-50%); } .ms-container:before, .ms-container:after { content: ""; position: absolute; top: 0; width: 80px; height: 100%; z-index: 1; pointer-events: none; } .ms-container:before { left: 0; background-image: linear-gradient(to right, #354051 25%, rgba(53, 64, 81, 0)); } .ms-container:after { right: 0; background-image: linear-gradient(to left, #354051 25%, rgba(53, 64, 81, 0)); } .ms-track { position: relative; left: calc(50% - 62.5px); white-space: nowrap; font-size: 0; list-style: none; padding: 0; margin: 0; will-change: transform; } .ms-slide { display: inline-flex; align-items: center; justify-content: center; width: 125px; height: 540px; font-size: 100px; font-family: "Roboto Mono", monospace; color: #FFFFFF; cursor: default; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; will-change: transform; } (function() { // Variables to use later var root = document.documentElement; var container = document.querySelector('.container'); var button = document.querySelector('.button'); var counter = document.querySelector('.counter'); var running = false; var timer = null; var seconds = 0; var secondsInitial = 0; // Initializing the slider var ms = new MomentumSlider({ el: container, // HTML element to append the slider range: [1, 60], // Generar los elementos del slider usando el rango de números definido loop: 2, // Hacer infinito el slider, añadiendo 2 elementos extra en cada extremo style: { // Estilos para interpolar // El primer valor corresponde a los elementos adyacentes // El segundo valor corresponde al elemento actual transform: [{scale: [0.4, 1]}], opacity: [0.3, 1] } }); // Simple toggle functionality button.addEventListener('click', function () { if (running) { stop(); } else { start(); } running = !running; }); // Start the countdown function start() { // Disable the slider during countdown ms.disable(); // Get current slide index, and set initial values seconds = ms.getCurrentIndex() + 1; counter.innerText = secondsInitial = seconds; root.style.setProperty('--progress', 0); // Add class to trigger CSS transitions for `running` state container.classList.add('container--running'); // Set interval to update the component every second timer = setInterval(function () { // Update values counter.innerText = --seconds; root.style.setProperty('--progress', (secondsInitial - seconds) / secondsInitial * 100); // Stop countdown if it's finished if (!seconds) { stop(); running = false; } }, 1000); } // Stop the countdown function stop() { // Enable slider ms.enable(); // Clear interval clearInterval(timer); // Reset progress root.style.setProperty('--progress', 100); // Remove `running` state container.classList.remove('container--running'); } })(); Навигация по записям January 1 Scratch & Win