绑定事件处理程序的keydown监听功能JavaScript jQuery [英] bind event handler on keydown listen function JavaScript jQuery

查看:260
本文介绍了绑定事件处理程序的keydown监听功能JavaScript jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个处理程序绑定到一个事件。事件是一个键控功能。处理程序将侦听命中变量以产生两个条件之一。第一个条件(奇数点击)将执行1个功能,第二个(偶数次命中)将执行另一个功能。要详细说明,第一个功能将滚动到一个元素,第二个将滚动到另一个元素

I am trying to bind a handler to an event. The event is a keydown function. The handler will listen for hit variables to produce one of two conditions. The 1st condition (odd number of hits) will perform 1 function, the 2nd (even number of hits) will perform another function. To elaborate, the 1st function will scroll to one element, the 2nd will scroll to another element

FIDDLE

以上是一个演示的链接,您可以看到一个讨厌的错误。

Above is a link to a demo, there is a nasty bug which you can see.

唯一可以想到的是,第二个事件应修改以下内容:

The only thing I can think of is that the following should be revised for the second event:

.offset().top


推荐答案

声明命中在您的keydown功能之外,因此每次不会重置为0。

declare hits outside your keydown function so it doesn't get reset to 0 each time.

这篇关于绑定事件处理程序的keydown监听功能JavaScript jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆