Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anchor scrolling doesn't work properly. #292

Open
VincentVanDenBossche opened this issue Oct 2, 2017 · 3 comments
Open

anchor scrolling doesn't work properly. #292

VincentVanDenBossche opened this issue Oct 2, 2017 · 3 comments

Comments

@VincentVanDenBossche
Copy link

VincentVanDenBossche commented Oct 2, 2017

Hello, I am using slidebars for my onepager website. Its a great framework but I'm struggling with animating a smooth scroll anchor to anchor on my page. The scroll on the website of sliderbars (advanced usage) doesn't work properly so but I understand the principles so I made my own. The problem is it doesn't scroll to the anchor if you have already navigated on the website, like you can see on www.dart-development.be/woodsolutions.

This is how I code my smoothscroll

$('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) {
             $('[canvas="container"]').animate({
                 scrollTop: target.offset().top
            }, 1000);
            return false;
        }
    }
  });

Hope someone can help me!

@Walkeezy
Copy link

I'm experiencing the same issue. Anyone found a solution to this?

@JoryHogeveen
Copy link

@VincentVanDenBossche
It seems you've got this working now?

@Walkeezy
Can you share a link? There is no general solution in the current version of Slidebars. This is entirely related to your website since every site can have a different structure.
I've modified the Slidebars code in a WordPress plugin to remove the need of scrolling the canvas container and return to the default browser (body) scroll. This might be a better solution for you as well.
See my PR: #257

@Walkeezy
Copy link

Walkeezy commented Sep 27, 2018

I'm using the following workaround for now, but I might try your solution @JoryHogeveen, thanks!

$('[canvas="container"]').scrollTop(0); // Resetting scroll position
$('[canvas="container"]').animate({ scrollTop: $target.offset().top - headerheight }, 500);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants