JavaScript/JQuery 倒计时器具有多个间隔设置?
我想从一个数字开始倒计时,比如说 100。但我不希望倒计时很明显,比如以秒为单位。我想要 3 个如下所示的间隔,如果它们可以是随机的,那就更好了。每次数字发生变化,我都想设置一个 cookie 来保存新值。
- 2 秒
- 8 秒
- 14 秒
所以它的工作原理如下:
用户登陆页面,看到数字 100,然后 2,8 或 14 秒后, 100 递减到 99,依此类推,直到达到 0。假设用户看到 2 个间隔,剩下 98,该值应该在 cookie 中设置,因此当他们再次访问该页面,看到的不是 100,而是新值。
很难,有什么插件可以帮助我吗?
I want to countdown from a number, let's say 100. But I don't want the countdown to be obvious such as in seconds. I would like 3 intervals like below and if they could be random, that would be even better. Each number change, I want to setup a cookie that holds the new value.
- 2 seconds
- 8 seconds
- 14 seconds
So it works like so:
User lands on page, Sees the number 100, then either 2,8 or 14 seconds later, the 100 decrements down to 99 and so on until it hits 0. Say the user sees 2 intervals and is left with 98, that value should be set in the cookie, so when they visit the page again, the don't see 100, but the new value.
Hard, any plugins to help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 $.doTimeout() jQuery 插件以及 $.cookie() jQuery 插件如下:
HTML:
JavaScript:
这是未经测试的但应该能解决问题;希望有帮助!
You could use the $.doTimeout() jQuery Plugin along with the $.cookie() jQuery plugin together like this:
HTML:
JavaScript:
This is untested but should do the trick; hope it helps!