I have created a simple example where I aim to display the output of a JavaScript function on an HTML page.
Furthermore, I want to apply two different animations using CSS to this output.
When attempting to apply the animations (clockwise and counterclockwise spins) separately to two different divs, the code works as expected. However, when trying to make them work within the same div using span elements, the animations do not work.
Here is the code snippet:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>clock VS countclock</title>
<style>
@-webkit-keyframes rotating {
from {
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes rotating {
from {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
to {
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.rotating {
-webkit-animation: rotating 5s linear infinite;
-moz-animation: rotating 5s linear infinite;
-ms-animation: rotating 5s linear infinite;
-o-animation: rotating 5s linear infinite;
animation: rotating 2.5s linear infinite;
}
/* ANTIROTATING */
@-webkit-keyframes antirotating {
from {
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
to {
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
}
@keyframes antirotating {
from {
-ms-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
to {
-ms-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}
}
.antirotating {
-webkit-animation: antirotating 5s linear infinite;
-moz-animation: antirotating 5s linear infinite;
-ms-animation: antirotating 5s linear infinite;
-o-animation: antirotating 5s linear infinite;
animation: antirotating 5s linear infinite;
}
</style>
</head>
<body>
<!-- this works -->
<!-- <div style="text-align: center; font-size: 80px;" id="content2display1" ; class="rotating"></div>
<div style="text-align: center; font-size: 80px" id="content2display2" ; class="antirotating"></div> -->
<!-- this does NOT work -->
<span id="content2display1"; class="rotating"></span>
<span id="content2display2"; class="antirotating"></span>
<script>
function foo() {
rv_j = "hello"
rv_j = rv_j
document.getElementById('content2display1').innerHTML = rv_j
rv_i = "world"
rv_i = rv_i
document.getElementById('content2display2').innerHTML = rv_i
}
foo();
setInterval("foo();", 5000);
</script>
</body>
</html>
Is there a way to make the animation work using <span>
instead of separate <div>
elements?