Gap between external anchored link from submenu pages

17 replies · opened Dec 1, 2016

WWebink74Dec 1, 2016

Hello team,

I am experiencing an issue trying to link two submenu pages with anchored sections. I am using each tab for different pages and each drop down tab as internal links to scroll to sections inside the page. The issue appears when I am in a page and I want to go to a specific section of another page, resulting with a hidden top section below the header and submenu.

For instance I am on page #1, I click on the 1st dropdown tab of the 2nd submenu tab (--> anchored to 1st section of this 2nd page), the 2nd page is loaded but the scroll doesn't bring me exactly to the top of the section but a little bit below resulting with a hidden beginning of the section.

As 2 pictures are better than a long text, see the enclosed screenshots.

Hope my explanations are understandabled !
Thank you for advising me.

SSemicolon WebSTAFFDec 4, 2016

Hello,

Thank You for the Explanations! It was Really Helpful in understanding the Core of the Issue! :)

Actually, One Page Scrolling Functionality works only Same Page Links and this functionality is not included by Default in Canvas but can be Definitely Implemented. Simply add the following JS code at the bottom of the Page just after the js/functions.js JS File Linking to enable this:


    jQuery(document).ready( function(){
        setTimeout(function() {
            if (location.hash) {
                window.scrollTo(0, 0);
            }
        }, 1);
    });

    jQuery(window).on('load', function(){
        var divScrollToAnchor = window.location.hash;

        if( typeof divScrollToAnchor !== 'undefined' ) {
            var t = setTimeout( function(){
                $('html,body').stop(true).animate({
                    'scrollTop': $( divScrollToAnchor ).offset().top - 100
                }, 700, 'easeOutQuad');
            }, 1000);
        }
    });

This will definitely work fine. Let us know if we can help you with anything else or if you find any issues.

WWebink74Dec 6, 2016

Glad you understood, thank you it works fine!
Just a question, would it be possible to calculate the offset for each anchor when pages load. For now I have to set the scrollTop manually increasing or decreasing the substituted value in each page I need following what element's height there is before first anchored section. (page #1 :'scrollTop': $( divScrollToAnchor ).offset().top - 50 and page #2 :'scrollTop': $( divScrollToAnchor ).offset().top - 150 ).

WWebink74Dec 6, 2016

This would allow to place the script you provide me in the functions.js file to not having to duplicate it on each page (as submenu pages are going to be the core files of the site).

WWebink74Dec 12, 2016

Any tips about it?

WWebink74Dec 16, 2016

Hi team,

Would you have an advice about this point?

Thank you

SSemicolon WebSTAFFDec 16, 2016

Hello,

Apologies about the Delays! We were actually working on a Proper Modular Code for you. :)

Consider adding the data-offset="50" to the Section you are scrolling to. Example: If you are scrolling to the #section-about Section, then your code would be:


	...

and then use the following JS Code:

jQuery(document).ready( function(){
	setTimeout(function() {
		if (location.hash) {
			window.scrollTo(0, 0);
		}
	}, 1);
});

jQuery(window).on('load', function(){
	var divScrollToAnchor = window.location.hash;

	if( typeof divScrollToAnchor !== 'undefined' ) {
		var getOffset = $( divScrollToAnchor ).attr('data-offset');

		if( getOffset ) {
			scrollOffset = Number( getOffset );
		} else {
			scrollOffset = 70;
		}

		var t = setTimeout( function(){
			$('html,body').stop(true).animate({
				'scrollTop': $( divScrollToAnchor ).offset().top - scrollOffset
			}, 700, 'easeOutQuad');
		}, 1000);
	}
});

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

WWebink74Feb 27, 2017

Hello team,

I have just seen the solution browsing my previous topics, really sorry for the none reply I haven't received the email.

Thank you it works well but the hash part of the URL doesn't refresh with the clic (when I click on an anchor link it scrolls to the section but the hash doesn't change keeping the previous section hash). Here is the syntax :


- [Section Title](page.html#section1)

- [Section Title](page.html#section2)

- [Section Title](page.html#section3)

Would you have an idea from what it comes from?

Other related question, I am experiencing different behaviours, could you tell me what is the better syntax :


- [Section Title](page.html#section2)

OR with the page file on both :


- [Section Title](page.html#section2)

OR with data-href instead of data-scrollto :


- [Section Title](#section2)

What is the difference between data-href and data-scrollto ?
Thank you!

WWebink74Feb 27, 2017

Sorry but I can't edit the post I just sent, I am always redirected to a page saying that I have not the licence for the support and I need to re-buy it while I can read and reply to post (and the support is not outdated)!?

So in order to make it more readable, I repost it :

Hello team,

I have just seen the solution browsing my previous topics, really sorry for the none reply I haven’t received the email.

Thank you it works well but the hash part of the URL doesn’t refresh with the clic (when I click on an anchor link it scrolls to the section but the hash doesn’t change keeping the previous section hash). Here is the syntax :


- [Section title](page.html#section1)

- [Section title](page.html#section2)

- [Section title](page.html#section3)

Would you have an idea from what it comes from?

Other related question, I am experiencing different behaviours, could you tell me what is the better syntax :

`

OR with the page file on both :
`

OR with data-href instead of data-scrollto :
`

What is the difference between data-href and data-scrollto ?
Thank you!

WWebink74Mar 1, 2017

Any tips?

WWebink74Mar 7, 2017

???

WWebink74Mar 20, 2017

Could you please make a hint here?

SSemicolon WebSTAFFMar 27, 2017

Hello,

Thank You for your Patience!

The data-scrollto is used for Independent Scroll To Links. However, data-href is used only inside a One Page Menu. According to your Usage Requirements, you should use the data-scrollto Functionality.

Please use the following code:


- [Section title](page.html#section1)

and then use the following code to update the linkScroll: function() Function Block entirely in the js/functions.js File, so that the Browser Address can be changed:

linkScroll: function(){
	$("a[data-scrollto]").click(function(){
		var element = $(this),
			divScrollToAnchor = element.attr('data-scrollto'),
			divScrollSpeed = element.attr('data-speed'),
			divScrollOffset = element.attr('data-offset'),
			divScrollEasing = element.attr('data-easing'),
			divScrollHighlight = element.attr('data-highlight');

			if( !divScrollSpeed ) { divScrollSpeed = 750; }
			if( !divScrollOffset ) { divScrollOffset = SEMICOLON.initialize.topScrollOffset(); }
			if( !divScrollEasing ) { divScrollEasing = 'easeOutQuad'; }

		$('html,body').stop(true).animate({
			'scrollTop': $( divScrollToAnchor ).offset().top - Number(divScrollOffset)
		}, Number(divScrollSpeed), divScrollEasing, function(){
			if( divScrollHighlight ) {
				if( $(divScrollToAnchor).find('.highlight-me').length > 0 ) {
					$(divScrollToAnchor).find('.highlight-me').animate({'backgroundColor': divScrollHighlight}, 300);
					var t = setTimeout( function(){ $(divScrollToAnchor).find('.highlight-me').animate({'backgroundColor': 'transparent'}, 300); }, 500 );
				} else {
					$(divScrollToAnchor).animate({'backgroundColor': divScrollHighlight}, 300);
					var t = setTimeout( function(){ $(divScrollToAnchor).animate({'backgroundColor': 'transparent'}, 300); }, 500 );
				}
			}
			if( history.pushState ) {
				history.pushState( null, null, divScrollToAnchor );
			} else {
				window.location.hash = divScrollToAnchor;
			}
		});

		return false;
	});
},

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

WWebink74Mar 27, 2017

Ok I will try it thank you

WWebink74Apr 13, 2017

Hello,

I have a new question about the code you provide me about the offset on page-section :

jQuery(document).ready( function(){
    setTimeout(function() {
        if (location.hash) {
            window.scrollTo(0, 0);
        }
    }, 1);
});
 
jQuery(window).on('load', function(){
    var divScrollToAnchor = window.location.hash;
 
    if( typeof divScrollToAnchor !== 'undefined' ) {
        var getOffset = $( divScrollToAnchor ).attr('data-offset');
 
        if( getOffset ) {
            scrollOffset = Number( getOffset );
        } else {
            scrollOffset = 70;
        }
 
        var t = setTimeout( function(){
            $('html,body').stop(true).animate({
                'scrollTop': $( divScrollToAnchor ).offset().top - scrollOffset
            }, 700, 'easeOutQuad');
        }, 1000);
    }
});

When I click on an anchor, even without the data-offset attribute, it seems jumping first to top, jumping back to the current position and finally scrolling to desired section. The point is that it result in a kind of a flash when I click on an anchored link in the same page.
I have tried to remove the function and it doesn't make the behavior.

Could you let me know what to change in the function, in order to keep the functionality of the data-offset ?

SSemicolon WebSTAFFApr 15, 2017

Hello,

We could not replicate this behavior on our Demos. Can you please provide us with a Live URL so that we can check out the exact issue and provide you with a more accurate solution for this. Thanks for your Patience.

Meanwhile, do let us know if we can help you with anything else or if you find any further issues with Canvas.

WWebink74Apr 19, 2017

I am really sorry to not being able to provide you a live URL as I am working on a localhost.

Let me describe it to you better :
I have a page with a one page navigation menu with 5 main tabs (pointing to other pages) and, for each one, a number of sub tabs pointing to an anchor of a section of the current page (current main tab).
I don't know why, there is a gap between the anchored section and the top of this one hiding the title and content. So you provided me the function above, I set it and then experienced the "flash" behavior.

SSemicolon WebSTAFFApr 23, 2017

Hello,

We Really Apologize but without a Live URL, we cannot be of much help since we need to fully understand the issue and debug it on Our Browsers to be enable to provide you with an accurate solution. Providing Solutions based on assumptions will always take very long. We strongly recommend you to provide us with a Sample Live URL so that we can provide you with proper fixes. Thanks for your Patience.

Meanwhile, do let us know if we can help you with anything else or if you find any further issues with Canvas.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard