How to make loading animation using symbols, as it was on DOS or in Ubuntu terminal?
And these characters:
- -
- /
- |
- \
I thought CSS animation (maybe), but no. This applies to JS, and how to make it: I do not understand. How to make such an animation?
How to make loading animation using symbols, as it was on DOS or in Ubuntu terminal?
And these characters:
I thought CSS animation (maybe), but no. This applies to JS, and how to make it: I do not understand. How to make such an animation?
You can do this with the help of a single CSS:
body {background-color: blue;} .loader:before { color: white; content: ''; animation: loader 1s infinite; } @keyframes loader { 0% { content: '--' } 25% { content: '/' } 50% { content: '|' } 75% { content: '\5c' } 100% { content: '--' } } <div class="loader"></div> But unfortunately this method will only work in small circles of browsers, among which Google Chrome. So it’s still better to use JavaScript for cross-browser compatibility:
setInterval(function() { document.getElementById('loader').innerHTML = '--'; setTimeout(function() { document.getElementById('loader').innerHTML = '/'; setTimeout(function() { document.getElementById('loader').innerHTML = '|'; setTimeout(function() { document.getElementById('loader').innerHTML = '\'; }, 250); }, 250); }, 250); }, 1000); body {background-color: blue;} #loader { color: white; } <div id="loader">--</div> content property there, although in Chrome its animation is supported. - Vadim OvchinnikovIn order for this solution to be supported by different browsers, you must use the Javascript function setInteval , create an array of strings for animation, and take the following line for each step at index:
(function() { var chars = [ "--", "/", "|", "\\" ]; var index = 0; setInterval(function() { document.getElementById("loader").innerText = chars[index]; ++index; if (index === chars.length) index = 0; }, 250); })(); body { background-color: blue; } #loader { color: white; } <div id="loader"></div> Source: https://ru.stackoverflow.com/questions/612048/
All Articles