Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

countdown倒计时组件存在显示问题 #194

Open
mirari opened this issue Jan 16, 2019 · 1 comment
Open

countdown倒计时组件存在显示问题 #194

mirari opened this issue Jan 16, 2019 · 1 comment
Labels

Comments

@mirari
Copy link

mirari commented Jan 16, 2019

比如倒计时从02:01开始,下一秒会显示01:60,而不是02:00
原因是源码中的

let diff = (this.options.date.getTime() - Date.now() + this.options.offset) / 1000

diff绝大多数时候都是一个带毫秒数的浮点数,这就导致后面的

if (diff >= 60) {
            dateData.min = Math.floor(diff / 60)
            diff -= dateData.min * 60
        }

几乎不会有等于60的情形,diff最后运算结果成为sec,这总是一个1-60的数字,而非预期的0-59。

我的解决方案是将diff先取整

 let diffOrigin = (this.options.date.getTime() - Date.now() + this.options.offset) / 1000
 let diff = Math.floor(diffOrigin)

毫秒的运算要改成从原始的浮点数取值

dateData.millisec = diffOrigin % 1 * 1000
@mirari mirari changed the title 倒计时组件存在显示问题 使用时间戳创建的倒计时组件存在显示问题 Jan 16, 2019
@mirari mirari changed the title 使用时间戳创建的倒计时组件存在显示问题 使用时间戳创建的countdown倒计时组件存在显示问题 Jan 16, 2019
@mirari mirari changed the title 使用时间戳创建的countdown倒计时组件存在显示问题 countdown倒计时组件存在显示问题 Jan 16, 2019
@skyvow
Copy link
Member

skyvow commented Jan 19, 2019

@mirari 感谢反馈,也希望能够提 PR

@skyvow skyvow added the bug label Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants