views:

100

answers:

3

Hello,

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

A: 

Well, if you got some "trigger" on that an user may choose between keyboard and mouse you can .unbind() the mouse event handler (on keyboard selection).

$('#content tr').unbind('mouseover');

That should be done more detailed by unbinding a specific event handler, I'll give you an example of this if this is what you are looking for.

jAndy
I will try it thanks
Crupuk
hargggThe tr in #content div is added with ajax, and so doesn't exist when page is loaded..So if i try to bind('mouseover') they don't work..i don't think is the prolem is linked but.. unbind work, not bind :-(
Crupuk
A: 

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

});
patrick dw
I already try this..And they don't work, because the scrollTo plugin set keyboardScroll=false befor the scroll end.. And so, mouseover is triggered.. :-(
Crupuk
@Crupuk - I see now you have the `keyNav` variable. Strange that it doesn't work. The plugin docs state that `onAfter` runs after the animation is complete.
patrick dw
Look this code :$('#content tr').unbind('mouseover');$("#content").scrollTo('-='+$("#"+id).outerHeight(true)+'px',{ 'onAfter': function() { alert("rebind"); $('#content tr').bind('mouseover'); } });The unbind event work , but not the bind..Maybe, it's because the #content > table > tr is added dynamicaly with ajax. So, the mouseover is define in the ajax success method and the bind is called outside because keypress is set on "document" and doesn't need to be placed in ajax()(it's not simple... :-s --> Sorry )
Crupuk
`bind()` will work as long as the element is *currently* on the page. It doesn't matter how it got there. I wouldn't use bind/unbind since I can't think of any reason a variable wouldn't work. If the `keyNav` variable is out of the scope of the `mouseover` event, then it wouldn't work. Can't tell without seeing more code.
patrick dw
After some test : It's logic : onAfter set keynav = false, so mouseover is detected because the mouse is over a element, so he's triggered... I have tested to set keyNav=false on mousemove, but no more effect..
Crupuk
@Crupuk - Oh, I thought the issue was that during the scroll, several items were getting the `mouseover` as they passed the mouse pointer. Yes, the one the mouse is pointing to when the scroll stops will probably get the `mouseover`.
patrick dw
@patrick : And do you have an idea to get this working ?Thanks
Crupuk
@Crupuk - So when the scroll stops, you want the `mouseover` to not trigger. But when *should* it trigger? If the user moves the mouse after the scroll stops, should the `mouseover` fire then?
patrick dw
@patrick : Yes both !!
Crupuk
Don't forgeve me plz ?
Crupuk
@crupuk - Sorry, I let this one slip. I'll have another look later today. Just to be clear, when the animation stops, the `mouseover` should not fire, but *as soon as* the user moves the mouse, it should fire. Is that right?
patrick dw
@crupuk ...(see above comment), but first, try changing your `mouseover` handler to `mouseenter` instead and see if that helps.
patrick dw
@patrick : Thanks , mouseenter doesn't help...And for the post above it's exactly what i want..But because the event (mouse* ) trigger AFTER scrollTo.. i don't know how to block it..
Crupuk
@crupuk - in the `onAfter`, try assigning the `keyNav` variable in a short timeout: `'onAfter': function() { setTimeout( function() { keyNav=false; }, 500 ); }`
patrick dw
it works, thanks you
Crupuk
A better way is to use e.pageX and e.pageY , test if the value change, if they don't change, don't mouseover..
Crupuk
@Crupuk - That's a clever idea. Only downside I see is if the user bumps the mouse just a little during the scroll.
patrick dw
A: 

To my knowledge this isn't something that would work across differnt browsers. Behaviors like this are very much up to the programmer of each browser, and they different don't play nice across the board. I don't think most browsers run the mouse-over interface while scrolling.

What you could try (and this won't be easy), is grab the mouse coordinates of the page, and the scroll% of the page, and then calculate where the mouse would be.

The page over here might help give you a good start.