pullo — 2011-04-04T13:55:16-04:00 — #1
I have a page divided into various divs, each with an unique id.
The user can navigate through these divs using a nav bar at the top of the screen, which is pinned in position with 'position:fixed'.
I have attached an event handler to the links in the nav bar. Correspondingly when the user uses the nav bar to move around the page the desired event always fires.
However, if the user uses the address bar to navigate nothing happens, e.g. if someone is viewing "www.mysite.com/#panel1" and then types into the address bar "www.mysite.com/#panel2", they are moved to the corresponding section of the site, but no event fires.
Is there any way to achieve this?
Thanks in advance.
logic_ali — 2011-04-04T14:52:48-04:00 — #2
I don't think there's an event that notifies a hash change.
You could use the onscroll event to poll location.hash, but it doesn't allow for manual scrolling. I would use onscroll to monitor which of the group of relevant elements is currently displaying the most area within the viewing pane.
pullo — 2011-04-04T15:30:01-04:00 — #3
Hi thanks for that,
I'm using jQuery and following your advice I came up with the code:
Now I can detect when scrolling starts. This also fires when navigating via the address bar as previously described and also when navigating via the back button. So this is definitely progress. Thanks very much!
However, what I would really like to do, is not to fire an event when scrolling starts, rather when it stops.
Is this possible?
If so, could you give me a pointer as to how I might acheive this?
Thanks very much.
logic_ali — 2011-04-04T18:50:46-04:00 — #4
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<style type = "text/css">
function myFunc( )
document.title = "Scrolling stopped at " + new Date().getTime();
window.onscroll = ( function ( funcRef )
clearTimeout( t );
t = setTimeout( funcRef, 300 );
})( myFunc );
pullo — 2011-04-05T17:17:15-04:00 — #5
Thank you ever so much for that.
The code you supplied really pointed me in the right direction.
Now everything works just as it should.