Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Dreamer

How to create anchor menu to horizontal scrolling page?

Recommended Posts

Hi, how can i create anchor links for a horizontal scrolling?

My version is not working correctly: 

$(".menu-item").on("click", function (event) {
    event.preventDefault();
    var id = $(this).attr('href');
    var left = $(id).offset().left;
    $('body,html').animate({
        scrollTop: left
    }, 1500);
});

 

See the Pen BaKgLvx by dreamerweb (@dreamerweb) on CodePen

Link to post
Share on other sites

Hey Dreamer and welcome to the GreenSock forums. A few things going wrong here:

  1. Your ScrollTrigger's end is not what it should be. If you want the ScrollTrigger's duration to be 1 for 1 the duration of the horizontal section you should subtract out the width of the viewport from the end point.
  2. The offset that jQuery is giving you is not correct for the #contacts section. I don't know why but using the vanilla JS .offsetLeft works.
  3. I'd use GSAP's ScrollToPlugin because GSAP's performance is better than jQuery's. Also you have more flexibility using GSAP.

See the Pen YzqoNOK?editors=0010 by GreenSock (@GreenSock) on CodePen

  • Like 2
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×