我还有一个问题,因为回复是禁食我又回来了!!
我想使用“按键导航”,为此,我使用带有向下/向上键的按键事件)
当我的鼠标悬停在一个 div(与一张大 table 相对应的 div)上时,我按下了向下键:
我滚动到下一个 td + 更改 css 样式 + 删除当前样式
同样,对于每个事件......
所以,因为我的鼠标在主 div 上,每次我滚动(自动)到一个元素时,都会触发鼠标悬停事件..
所以,效果就错过了..
这是完美的脚本:
- 用户使用键盘导航:禁用鼠标悬停(因此只能使用向上/向下键更改样式)
- 用户不使用键盘:鼠标悬停改变样式
你能帮帮我吗?
代码:
$("#content tr").mouseover(function() {
$("#content tr.use,#content tr.sel").removeClass("use sel");
$(this).addClass("sel");
});
和键盘导航代码:http://pastebin.com/Hgn5Y1FV
(再次抱歉我的英语..)
谢谢
最佳答案
试试这个。每当您开始滚动(从箭头键开始)时,将其设置为 true,当滚动停止时,将其设置为 false。
var keyboardScroll = false; // Set to true when keyboard scroll begins
// and false when keyboard scroll ends
然后仅当 keyboardScroll 为 false 时才运行 mouseover
代码;
$("#content tr").mouseover(function() {
if( !keyboardScroll ) { // Run code only if keyboard scroll is not true
$("#content tr.use,#content tr.sel").removeClass("use sel");
$(this).addClass("sel");
}
});
关于javascript - jquery效果问题: How to detect if mouseover is triggered by scroll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3053056/