Jump to content
GreenSock

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

Passing an argument with ScrollTo not working

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

Sorry it was a dumb question, I managed to resolve it by just adding "return false;" inside the trigger function

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

    return false;
});
  • Like 1
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.
×