0

I need help, I'm building a one page layout webpage and I have a scroll to script but I want when I press the button in the nav bar class to appear. What I mean?

When ever I press a button it scrolls to the position but I want to see htttp://mysite.com/#top

This is what I have

    $(function(){
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
        var $target = $(this.hash);
        $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
        if ($target.length) {
            var targetOffset = $target.offset().top;
            $('html,body').animate({scrollTop: targetOffset - 100}, 800); /* Offest 100px because of the fixed nav manu */
            return false;
        }
    }
  });
});
Maverick
  • 876
  • 2
  • 12
  • 22
  • So - to restate your question for clarification... you currently have a system working where pushing a button will cause you to jump to the correct place on the page. You would like it to also change the displayed URL to reflect the jump. Is this correct? – Ben Barden Dec 17 '12 at 22:20
  • If that is, indeed, what you need, then apparently http://stackoverflow.com/questions/3338642/updating-address-bar-with-new-url-without-hash-or-reloading-the-page has the answer for you (though I admit it took me a while of reading to understand fully). – Ben Barden Dec 17 '12 at 22:22
  • That is it but where do I put it, total JS noob here. Sorry Thanks in advance – Maverick Dec 17 '12 at 23:34

1 Answers1

0

Perhaps I not fully understand the question, but if you want the hash (#top) to be displayed, you should just delete return false; from your code.

Filipp Zet
  • 35
  • 5