EN
JavaScript - rotate string (animation)
0 points
In this article, we would like to show you how to rotate string using JavaScript.
In this example, we create an animation that rotates the text placed in my-element
every 0.1s (100
ms).
xxxxxxxxxx
1
2
<html>
3
<body onload="startAnimation('my-element')">
4
<script>
5
6
function startAnimation(elementId) {
7
var element = document.querySelector('#' + elementId);
8
var text = element.innerText;
9
10
setInterval(function() {
11
text = text[text.length - 1] + text.substring(0, text.length - 1);
12
element.innerText = text;
13
}, 100);
14
}
15
16
</script>
17
<div id="my-element">Example text...</div>
18
</body>
19
</html>