I am trying to create a JavaScript counter:
function animateSun() {
var $elie = $("#sun");
$({
degree: 0
}).animate({
degree: 360
}, {
duration: 190999,
easing: 'linear',
step: function(val) {
now = Math.round(val);
if ((now == 5) || (now == 10) || (now == 15)) //increment the value on every 5th number
{
var i = 0;
$('#tam').text(i += 1);
}
$elie.css({
transform: 'rotate(' + now + 'deg)'
});
$('#demo').text('sec:' + now);
},
});
}
animateSun();
#sun {
position: absolute;
width: 55px;
height: 55px;
border: 1px solid red;
background-color: orange;
opacity: 0.9;
border-radius: 100%;
text-align: center;
top: 50%;
left: 50%;
animation: round 3s infinite linear;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<p id="demo"></p>
<p id="tam">0</p>
<p id="sun">sun</p>
The timer was running. When the time value reaches 5
, it should add 1
to #tam
. Then when it reaches 10
, #tam
should be incremented by another 1
to change the value to 2. However, this is not working as expected. Could someone please help me figure out how to increment the value of #tam
every time the count reaches a multiple of 5 and also display the changes on #demo
? Thank you in advance.