16. Spin counter with animationiteration 🔄

In this example below you will see how to do a 16. Spin counter with animationiteration 🔄 with some HTML / CSS and Javascript

Demo for my guide to CSS animation.Spin counter using animationiteration.A Guide to CSS Animation - Part 1

Thumbnail
This awesome code was written by jh3y, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright jh3y ©
  • HTML
  • CSS
  • JavaScript
    
<style>
  * {
    box-sizing: border-box;
  }
  html, body {
    align-items: center;
    background: linear-gradient(45deg, #1f3a93, #dadfe1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    margin: 0;
    min-height: 100vh;
    padding: 0;
    width: 100vw;
  }
  div {
    height: 50px;
    margin: 40px;
    width: 50px;
  }
  h1 {
    color: #fafafa;
    font-family: 'Arial', sans-serif;
  }
</style>
<div></div>
<h1>Span 0 times!</h1>


/*Downloaded from https://www.codeseek.co/jh3y/16-spin-counter-with-animationiteration-andx1f504-QxKeJQ */
    div {
  background: #f62459;
  animation: spin .5s infinite linear;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}


/*Downloaded from https://www.codeseek.co/jh3y/16-spin-counter-with-animationiteration-andx1f504-QxKeJQ */
    const spinner = document.querySelector('div')
const label = document.querySelector('h1')
let span = 0
const update = () => {
  span++
  label.innerText = `Span ${span} times!`
}

spinner.addEventListener('animationiteration', update)

Comments