How to use requestAnimationFrame to achieve the effect of price reduction?

< span class= "price" data-price= "123.59" data-starttime= "1509809876" > 123.59
< span class= "price" data-price= "255.76" data-starttime= "1509810123" > 255.76

there are several similar forms in the list page, with a price reduction of 0.10 yuan per second, then the number in the span continues to become smaller. The current problem is that each time the first price will move, and the rest will not move. Another problem is that I use settimeout to constantly get the current time and data-starttime to determine whether the price reduction time has begun, resulting in faster and faster animation flatness of requestAnimationFrame

.

ask for advice

Mar.23,2021

I don't understand. For this kind of DOM operation, the update frequency is not high. Generally, requestAnimationFrame is not needed. Is it not possible to go directly through setInterval (func, 1000) ?

for only the first item price will move, it may be the wrong DOM query.

if you use jq, the approximate code is as follows:

setInterval(function() {
    var time = new Date().getTime()
    $('.price').each(function() {
        if(time > $(this).attr('data-starttime')) {
             $(this).text(parseInt($(this).text()) - 0.1);
        }
    })
}, 1000)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3e7b2-2bc6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3e7b2-2bc6d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?