ChrisWojcik / single-page-nav

jQuery plugin that provides smooth scrolling and advanced navigation for single page websites.
http://chriswojcik.net/demos/single-page-nav/
161 stars 75 forks source link

Offset is ignored when accessing section directly #21

Open adamstrojil opened 8 years ago

adamstrojil commented 8 years ago

Hi Chris, the browser seems to ignore offset when I'm accessing to certain section directly via link or URL. When I'm using navigation menu for this, the offset works fine. I've tried same thing using your live demo and get the same results.

For exapmle: When I click on Section 2, it navigates me correctly to a section 2 + offset, but when I enter the address manually (http://chriswojcik.net/demos/single-page-nav/#section2) and press enter, it navigates me to the section 2 as well, but in this case without offset.

Is there any solution, how to get correct position in both cases?

abdulrazakshaikh commented 8 years ago

my navigation is set to top of section how can i give the offset to this jquery below

        $('#nav').singlePageNav({
            offset: $('#nav').outerHeight(),
            speed:2000,
            filter: ':not(.external)',
            updateHash: true,
            beforeStart: function() {
                console.log('begin scrolling');
            },
            onComplete: function() {
                console.log('done scrolling');
            }
        });
abdulrazakshaikh commented 8 years ago

samples attached is the samples images

adamstrojil commented 8 years ago

Hi 89abdul, what you have in your code means that the offset is equal to the height of an element with id 'nav'. Check if you have correct id for navigation in your HTML file ;) Or you can set offset manually in pixels. e.g. offset:200,

abdulrazakshaikh commented 8 years ago

nice its working thanks adamstrojil

JonCatmull commented 8 years ago

This is simply not handled by this plugin (only handles clicks), the reason it works (minus the offset issue) is because that is a default browser behaviour to try and match whatever is after the # to an id in the document. If i have time I will fix and submit pull request.

JonCatmull commented 8 years ago

I have submitted a pull request in which I have fixed this as best I can. Tricky issue as browsers do not allow preventing of the automatic behaviour. https://github.com/JonCatmull/single-page-nav