egr103
egr103

Reputation: 4008

Append div to body when URL hash # changes

I'm using curtain.js and would like to keep a DIV (which holds navigation) visible at all times except for when the user is looking at the very first panel, i.e. at the top of the page.

Currently the DIV resides within panel two

I'm thinking perhaps of using the hash change as you scroll through the page to trigger an append to the body. Curtain.js creates an individual URL for each panel and the URL changes each time a panel is brought into view.

I can append the div to the body (below) but I need to work out when to do this but I am unsure how? Could anyone help me out?

$("body").append($('.nav-wrap'));

Upvotes: 1

Views: 418

Answers (3)

egr103
egr103

Reputation: 4008

Ok well instead of using some hacky solution, after much digging around in the plugin's file, I just added:

$("body").append($('.nav-wrap'));

to the setHash function on line 491. Works a treat.

Upvotes: 0

Ram
Ram

Reputation: 144699

you can use onhashchange event:

The hashchange event fires when a window's hash changes

$(window).bind('hashchange', function() {
   $("body").append($('.nav-wrap'));
})

Upvotes: 1

pdjota
pdjota

Reputation: 3243

You can use JQuery to bind the Event

$(window).bind('hashchange', function(){ ... });

And add some workarounds for when it doesn't have the onhashchange event. jQuery - hashchange event

Upvotes: 0

Related Questions