需要使用 jquery 计时事件的帮助
这是我的代码:
tripper = 2;
$("#topheader").mousewheel(function(event, delta) {
if (tripper == 2){
startPlace = $("#content").scrollLeft();
startCounter = something;
tripper = 1;
} else {
currentPlace = $("#content").scrollLeft();
if(startCounter < 100){ // milliseconds
distanceMoved = currentPlace - startPlace;
if(distanceMoved > 100){
slideRight();
} else if(distanceMoved < -100){
slideLeft();
}
} else {
tripper = 2;
}
}
}
第一次通过此函数检查 100 毫秒是否已通过的正确方法是什么?在代码的第五行中,我有变量“something”,需要用某种计数器替换它。或者也许我正在以完全错误的方式处理这个问题。建议?
Here's my code:
tripper = 2;
$("#topheader").mousewheel(function(event, delta) {
if (tripper == 2){
startPlace = $("#content").scrollLeft();
startCounter = something;
tripper = 1;
} else {
currentPlace = $("#content").scrollLeft();
if(startCounter < 100){ // milliseconds
distanceMoved = currentPlace - startPlace;
if(distanceMoved > 100){
slideRight();
} else if(distanceMoved < -100){
slideLeft();
}
} else {
tripper = 2;
}
}
}
What is the proper way to check if 100 milliseconds has passed sense the first time through this function? In the 5th line of code i have the variable "something" which needs to be replaced with a counter of some sort. Or maybe I'm going about this in an entirely wrong way. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以像这样实例化一个“Date”对象:
稍后您可以创建另一个对象:
减法给出以毫秒为单位的差异:(
当两个日期值出现在减法的任一侧时,从“Date”到“Number”的强制转换是隐式的转换就像调用“now.getTime()”。)
You can instantiate a "Date" object like this:
Later you can make another one:
Subtraction gives the difference in milliseconds:
(The coercion from "Date" to "Number" is implicit when the two date values appear on either side of the subtraction operator. The conversion is just like calling "now.getTime()".)
以下代码未经测试,但基本上,在 100 毫秒后,它应该将
timeout
重置回 null 并最终将tripper
设置回 2;The following code it is untested but basically, after 100 milliseconds, it should reset
timeout
back to null and ultimately settripper
back to 2;