- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在特定时间后触发一些事件。计时器应该是可暂停的。这是代码: http://jsfiddle.net/xsH8v/
问题是我怎样才能触发这个
if (Clock.totalSeconds >= givenTime){
alert('time is up!');
}
我把它放在 document.ready
里了。但是当时间到了时它不会被解雇。我认为问题在于根本没有调用该函数。如果是这样,我该如何触发它?
最佳答案
您的方法不起作用,因为 if 语句只计算一次;在文档加载时。要解决此问题,您需要添加每次更新 totalSeconds 时都会检查的回调。
这是我的解决方案; fiddle here
您可以使用 Clock.at(time, callback)
添加函数,如下所示:
Clock.at(10, function() {/* 10 秒过去了 */});
var Clock = {
totalSeconds: 0,
handlers: [],
start: function () {
var self = this;
this.interval = setInterval(function () {
self.totalSeconds += 1;
sec = parseInt(self.totalSeconds % 60)
min = Math.floor(self.totalSeconds / 60 % 60)
hour = Math.floor(self.totalSeconds / 3600)
$("#hour").text(hour);
$("#min").text(min);
$("#sec").text(sec);
// Fire each expired handlers
self.handlers = self.handlers.filter(function(handler) {
if (self.totalSeconds >= handler.time) {
// Fire the handler then remove it
handler.func();
return false;
}
return true;
})
}, 1000);
},
pause: function () {
clearInterval(this.interval);
delete this.interval;
},
resume: function () {
if (!this.interval) this.start();
},
at: function(time, handler) {
// Handle expired handlers
if (this.totalSeconds >= time) handler();
// Add the handler to the queue
this.handlers.push({
time: time,
func: handler,
});
}
};
关于javascript - js : trigger a timing event after pause/resume,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21794971/
我的应用程序中有大约 100 多个表。大多数更新查询不会更新最后更新的时间列。有 100 多个查询,所以我有点怀疑修改所有查询以包括上次更新时间。我正在寻找的替代选项是为所有表创建一个 oracle
我的应用程序中有大约 100 多个表。大多数更新查询不会更新最后更新的时间列。有 100 多个查询,所以我有点怀疑修改所有查询以包括上次更新时间。我正在寻找的替代选项是为所有表创建一个 oracle
trigger.io 是否支持黑莓?如果没有,是否有任何计划支持它。 最佳答案 在移动方面,他们目前支持: iOS 4+ (iPhone 和 iPad) 安卓 2.0+ window 电话* 我不知道
这是 here 中的一个改写的问题。经过一些测试后,我隔离了问题,但没有解决它的线索。无需阅读上一个问题,这是简化的代码: 问题 -> trigger('click')执行,但在循环(间隔)函数内时不
我有一个程序,它会从 redis 数据存储中轮询某个键,并在该值满足某个条件时执行某些操作。 不过我觉得redis周期性的轮询效率很低,想知道redis有没有“触发”机制,当值发生变化满足条件时,触发
现在我的合作者收到这样的错误:[错误] Forge API call to app/f7617c848[...]adcbe/should_rebuild 出错:应用匹配查询不存在。 最佳答案 我们正在
当用户在我的 trigger.io iOS 应用程序(使用 Parse.com)上收到推送通知并希望在用户打开应用程序时清除徽章时,我将徽章设置为 1。有谁知道如何做到这一点? 谢谢! 最佳答案 有几
iPhone 启动图像现在显示太短,我想延长持续时间。 有没有办法在 config.json 中指定它? 最佳答案 更新 :从平台版本 v1.4.20 开始,您可以控制启动图像的可见性(http://
如何将文件下载到我的 trigger.io 应用程序?我的应用程序显示离线数据,但我需要我的应用程序如何从服务器下载和存储本地新鲜数据的方式。数据是一个带有项目数组和一些图像的 js 文件,每个图像都
为了根据条件更改 ListBoxItem 前景,我可以通过 DataTemplate.Triggers 来完成: ...
为了根据条件更改 ListBoxItem 前景,我可以通过 DataTemplate.Triggers 来完成: ...
我们正在构建一个以 Chaplin 为基础的 Trigger 应用程序。出于开发目的,如果我们可以使用 Assets 的绝对路径,那就太好了,比如: 是否可以在 Trigger 中执行此操作?
什么时候应该选择Style.Triggers,什么时候应该选择ControlTemplate.Triggers?使用一个比另一个有什么好处吗? 假设我有实现相同结果的这些样式:
在我的情况下,我将有一个带有自定义 url 架构的重定向 URL,例如 myapp://oauth 所以首先我会转发到我的 oauth 登录 url,然后我需要为位置更改注册一个事件处理程序,以检查它
我可以创建一个带有 OR 条件的 MYSQL TRIGGER 创建或替换触发器 TIGGER 名称插入之前或更新或删除 像这样(下面是 ORACLE TRIGGER): CREATE OR REPLA
有两个相同类型但存在于不同类中的属性。 FrameworkElement.Triggers Property Style.Triggers Property 这让我很困惑,所以我很少有问题要寻找答案:
我有兴趣为 trigger.io 编写 native 插件。 这是否已经可能或在路线图上? 最佳答案 这绝对在路线图上:我们从一开始就不允许这样做的主要原因是我们最初的主要重点是创建一个尽可能平稳和快
我知道如何缓存它,但我以后如何检索它。文档 ( http://docs.trigger.io/en/v1.4/features/cache.html ) 仅给出了使用图像的示例,要检索您需要做的就是获
在 AzureFunction1 中收到简短通知后,我需要一种可靠的方法将其快速保存,然后触发另一个 Azurefunction 来分析数据并根据分析进行其他操作。 我正在寻找一种向 azure fu
我正在尝试使用 Trigger.io 的框架构建一个流式音频应用程序。 看到它的 API 目前没有任何与音频相关的方法,我用基本的 HTML5 audio 对其进行了测试。标签。在这种情况下流式传输
我是一名优秀的程序员,十分优秀!