JQuery keydown() is being too hasty?

Use something other than :visible to mark the current element, as :visible will match for elements which are hid ing but aren't yet hidd en Demo using a class here.

Use something other than :visible to mark the current element, as :visible will match for elements which are hiding but aren't yet hidden. Demo using a class here.

I like that. It's quite simple. Not big fan of adding extra classes after I thought I was so clever for using :visible as the hook, but... you can't always win.

– Lollero Oct 22 at 23:23 You could use p:visible:not(:animated) as the selector, which doesn't involve any classes, but then it will ignore any key presses during animations. – icktoofay Oct 22 at 23:32.

This certainly won't be the cleanest solution but the first thing that came to mind was to keep track of the selected element in a variable: $('p:nth-child(4)').show(); var current = 3; $(document). Keydown(function(e){ if (e. KeyCode == 37) { $("p").

Stop(true, true). Current = (current - 1 Length - 1 : current - 1; $("p"). Eq(current).

Stop(true, true). Show(500); } else if (e. KeyCode == 39) { $("p").

Stop(true, true). Current = (current + 1 == $("p"). Length)?

0 : current + 1; $("p"). Eq(current). Stop(true, true).

Show(500); } }); Here's a working example. Note that this solution loops round once you reach the start/end and try to continue in the same direction. I don't know if that's what you're after, but it will be easy to modify.

The easiest solution, I think, seems to be to use the :animated selector to check whether there's an animated element present and, if there is, return false. Or, rather, to test that there's not an animation in process and, only if there is no current animation, animate the elements: $('p:nth-child(4)').show(); $(document). Keydown(function(e) { if (e.

KeyCode == 37) { if (!$('p:animated'). Length){ $('p:visible').prev(). Stop(true, true).

Show(500).next(). Stop(true, true). } return false; } else if (e.

KeyCode == 39) { if (!$('p:animated'). Length){ $('p:visible').next(). Stop(true, true).

Show(500).prev(). Stop(true, true). } return false; } }); JS Fiddle demo.

Edited to tidy up the above code, to reduce the nested if: $('p:nth-child(4)').show(); $(document). Keydown(function(e) { if (e. KeyCode == 37 &&!

$('p:animated'). Length){ $('p:visible').prev(). Stop(true, true).

Show(500).next(). Stop(true, true). } else if (e.

KeyCode == 39 &&! $('p:animated'). Length){ $('p:visible').next().

Stop(true, true). Show(500).prev(). Stop(true, true).

} }); JS Fiddle demo. References: :animated selector.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions