Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--
- New paste:
- https://pastebin.com/LE6pGXdr
- -->
- <!DOCTYPE html>
- <html>
- <head>
- <title>Animated Metronome</title>
- <style>
- :root {
- background-color: #2d2d2d;
- }
- .rolling_square {
- --bpm: 120;
- --duration: calc(240s / var(--bpm));
- position: absolute;
- left: 50%;
- top: 50%;
- width: 50vh;
- height: 50vh;
- background-color: #fff;
- transform: translate(-50%, -50%);
- }
- .rolling_square div {
- position: absolute;
- width: 50%;
- height: 50%;
- background-color: #ff5533;
- animation: roll var(--duration) ease-in infinite;
- animation-play-state:
- }
- @keyframes roll {
- 0% {
- transform-origin: top right;
- transform: translate(0%, 0%);
- }
- 25% {
- transform-origin: top right;
- transform: rotate(-90deg);
- }
- 25.000001% {
- transform-origin: bottom right;
- transform: translate(100%, 0) rotate(0deg);
- }
- 50% {
- transform-origin: bottom right;
- transform: translate(100%, 0%) rotate(-90deg);
- }
- 50.000001% {
- transform-origin: bottom left;
- transform: translate(100%, 100%) rotate(0deg);
- }
- 75% {
- transform-origin: bottom left;
- transform: translate(100%, 100%) rotate(-90deg);
- }
- 75.000001% {
- transform-origin: top left;
- transform: translate(0%, 100%) rotate(0deg);
- }
- 100% {
- transform-origin: top left;
- transform: translate(0%, 100%) rotate(-90deg);
- }
- }
- .slidecontainer {
- position: absolute;
- left: 50%;
- top: 24%;
- transform: translate(-50%, -50%);
- width: 45vh;
- display: flex;
- flex-direction: row;
- }
- .slidecontainer::before {
- transform: translateY(-60%);
- font-family: consolas;
- font-size: 20px;
- color: #fff;
- content: attr(data-bpm) " BPM";
- }
- .slider {
- -webkit-appearance: none;
- width: 100%;
- height: 10px;
- border-radius: 5px;
- background: #ddd;
- outline: none;
- }
- .slider::-webkit-slider-thumb {
- -webkit-appearance: none;
- appearance: none;
- width: 15px;
- height: 15px;
- border-radius: 50%;
- background: #ff5533;
- cursor: pointer;
- }
- </style>
- <script>
- var bpmSlider,met;
- window.onload = () => {
- bpmSlider = document.getElementById("bpm-slider");
- met = document.querySelector(".rolling_square div");
- setInterval(() => {
- let bpm = bpmSlider.value;
- met.style.setProperty('--duration', `calc(240s / ${bpm})`);
- document.querySelector(".slidecontainer").setAttribute("data-bpm", bpm);
- });
- document.querySelector(".rolling_square").onclick = () => {
- let playing = getComputedStyle(met).getPropertyValue("animation-play-state") == "running";
- if (playing) {
- met.style.setProperty("animation-play-state", "paused");
- met.style.setProperty("animation", "none");
- setTimeout(() => {
- met.style.setProperty("animation", "roll var(--duration) ease-in infinite");
- met.style.setProperty("animation-play-state", "paused");
- });
- return;
- }
- met.style.setProperty("animation-play-state", "running");
- }
- }
- </script>
- </head>
- <body>
- <div class='slidecontainer' data-bpm='120'>
- <input type='range' min='10' max='360' value='120' class='slider' id='bpm-slider'>
- </div>
- <div id='metronome' class='rolling_square'>
- <div id='ticker'></div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement