I have the following html:
<article class="layer" id="one"> </article>
<article class="layer" id="two"> </article>
<article class="layer" id="three"> </article>
<section class="cat" id="something">
<article class="layer" id="four"> </article>
<article class="layer" id="five"> </article>
</section>
<article class="layer" id="six"> </article>
…
I want to navigate with my keyboard through all articles. Like so …
var view,
next,
prev;
$(document).keydown(function(e) {
view = $('.layer:in-viewport');
next = view.next().attr('id');
prev = view.prev().attr('id');
switch (e.keyCode) {
case 38: // Up
if ( prev != undefined )
scroll($("#"+prev), true, 0);
break;
case 40: // Down
if ( next != undefined )
scroll($("#"+next), true, 0);
break;
}
});
This would work fine if all articles would be in the same container. However as you can see above I have a also sections that wrap those articles. I simply want to make it work as if there were no such sections and article#three jumps straight to article#four
Any idea how I could make that work?
edit:
The thing causing the bug in Firefox …
if ( top.location.hash ) {
hash = top.location.hash.substring(3);
catHash = hash.split('/')[1];
if ( catHash !== undefined )
scroll($("#"+catHash), false, 0);
else
scroll($("#"+hash), false, 0);
if ( hash != "index" && !isiPhone() )
$('#top').slideDown();
}
Where only those 4 lines cause the bug …
if ( catHash !== undefined )
scroll($("#"+catHash), false, 0);
else
scroll($("#"+hash), false, 0);
This few lines only check on page-load if a hash is existing in the current top.location.
So if the url is looking like this www.something.com/#!/category/idOfElement I want to jump to that location on the page.
Why could those 4 lines cause this bug only in firefox?
The easiest way to select the “real” next
<article>elements is by using the.indexand.eqmethods.