spip232
V2EX  ›  问与答

如何使用 requestAnimationFrame 实现降价效果?

  •  
  •   spip232 · Jul 2, 2018 · 1600 views
    This topic created in 2898 days ago, the information mentioned may be changed or developed.

    123.59 255.76

    列表页面中有多个类似以上形式的的,假设每秒降价 0.1 元,那么 span 内的数字就不断的变小,目前遇到的问题是每次只能实现第一条价格会动起来,后面的都不动,另外一个困扰是,我使用了 settimeout 来不断获取当前时间和 data-starttime 判断降价时间是否开始了,导致 requestAnimationFrame 的动画平率越来越快

    求大神指点

    1 replies    2018-07-02 23:11:11 +08:00
    spip232
        1
    spip232  
    OP
       Jul 2, 2018
    <span class="price" data-price="123.59" data-starttime="1509809876">123.59</span>
    <span class="price" data-price="255.76" data-starttime="1509810123">255.76</span>

    形式如上
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1670 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:21 · PVG 00:21 · LAX 09:21 · JFK 12:21
    ♥ Do have faith in what you're doing.