Andrey Shitov
Arrow navigation 23 December 2005 |
|
Task: | Desribe our ways. | ||
At www.artlebedev.com you can page through Routine, Process and Illustrations in Daily Section by pressing ← and → holding down the Ctrl key.
Its easy to guess what needs to be done for this. The script has to include references to the next and the previous page and a keyboard event handler.
Where to put the references? Well, it doesnt really matter. Lets use <link>
tags providing appropriate ids:
|
This code also serves another purposesome browsers recognize these tags and display extra buttons in the navigation panel.
And here comes the onkeydown
event handler:
|
Now, just wait for a click on the arrow:
|
Events |
Handling keyboard events is a rather trivial task, however there is often plenty of room to improve your code. |
Opera is an exception. It runs the handler after it has performed the default operation (combination Ctrl + arrow key is reserved by the browser). So, using Opera you should press Shift in addition to Ctrl which makes the three-key combination for navigating the <link>
references.
When you do things like that, carefully decide on what page is to be considered the next or the previous. For example, in our portfolio you navigate forward and back time-wise, while in Yandex, if you sort search results by date, its the other way round.