Jquery效果问题:如何检测mouseover是否是由滚动触发的?

发布于 2024-09-05 12:22:03 字数 681 浏览 2 评论 0原文

我还有另一个问题,因为这里的回复太快了,所以我又回来了!

我想使用“按键导航”,为此,我使用带有向下/向上键的按键事件)

当我的鼠标位于div(包含一张大桌子的div)上并且我拉下键时:

我滚动到下一个td + 更改 css 样式 + 删除当前样式

再次,对于每个事件..

因此,因为我的鼠标位于主 div 上,每次我滚动(自动)到某个元素时,都会触发 mouseover 事件..

所以, 用户

这是完美的脚本:

  • 用户使用键盘导航:鼠标悬停被禁用(因此只能使用向上/向下键更改样式)
  • 不使用键盘:鼠标悬停更改样式

你能帮我吗?

代码:

$("#content tr").mouseover(function() {
    $("#content tr.use,#content tr.sel").removeClass("use sel");
    $(this).addClass("sel");
});

键盘导航代码: http://pastebin.com/Hgn5Y1FV

(再次抱歉我的英语。 。 )

谢谢

I have another problem, and because the reply is to fast here i come back again !!

I would like to use "key navigation" and for that, i use the keypress event with down/up key )

When my mouse is over a div (div who's contenaing a big table) and i pull the down key :

i scroll to next td + change css style + remove the current style

And again, for each event..

So, because my mouse is over the main div, each time i scroll (auto) to a element, the mouseover event is triggered ..

And so, the effect is missed..

This is the perfect script :

  • User use keyboard navigation : Mouseover is disabled (so style change only with up/down key)
  • User don't use keyboard : mouseover change the style

Could you help me ?

The code :

$("#content tr").mouseover(function() {
    $("#content tr.use,#content tr.sel").removeClass("use sel");
    $(this).addClass("sel");
});

And the keyboard navigation code : http://pastebin.com/Hgn5Y1FV

(Sorry again for my english.. )

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

百思不得你姐 2024-09-12 12:22:03

试试这个。每当滚动(从箭头键)开始时,将其设置为 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");
    }

});

Try this. Whenever your scrolling (from the arrow keys) starts, have it set a flag to true, and when the scrolling stop, set the flag to false.

var keyboardScroll = false;  // Set to true when keyboard scroll begins
                             //     and false when keyboard scroll ends

Then have the mouseover code run only if keyboardScroll is false;

$("#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");
    }

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文