Jump to content
Search Community

Passing an argument with ScrollTo not working

Pola86 test
Moderator Tag

Go to solution Solved by Pola86,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hello everyone,

 

I'm having a problem with my scrollTo function.

I'm building an horizontal slider scrollable with buttons but there's something weird happening.

 

Here's an example of what i'm trying to accomplish with working code:

// the function

function goTo() {
    e.preventDefault;

    TweenLite.to('.wrapper', 1, {
        scrollTo: {
            x: $('#slide-glasses-2').position().left
        },
        ease: Power2.easeOut
    });
}

// the trigger

$("*[href^='#']").click(function() {
    goTo();
});

Point is I don't want to call the function for every button so I wrote this:

// the function

function goTo(target) {
    TweenLite.to('.wrapper', 1, {
        scrollTo: {
            x: $(target).position().left
        },
        ease: Power2.easeOut
    });
}

// the trigger

$("*[href^='#']").click(function() {
    var target = $(this).attr('href');

    goTo(target);
});

This doesn't work, I mean the click event brings me to the exact slide but without the scrolling animation.

Any suggestions?

 

Thx everyone

 

 

 

See the Pen NbLeZa by Polenji86 (@Polenji86) on CodePen

Link to comment
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.
×
×
  • Create New...