开发者

Jquery effect problem : How to detect if mouseover is triggered by scroll?

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 m开发者_运维技巧y 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


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

});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜