Share Posted December 13, 2016 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 More sharing options...
Author Share Posted December 13, 2016 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; }); 1 Link to comment Share on other sites More sharing options...
Share Posted December 13, 2016 Seems to be working... See the Pen oYaWOB?editors=0010 by osublake (@osublake) on CodePen And you can do bezier easing using CustomEase. 1 Link to comment Share on other sites More sharing options...
Author Share Posted December 13, 2016 Seems to be working... See the Pen oYaWOB?editors=0010 by osublake (@osublake) on CodePen And you can do bezier easing using CustomEase. Thx OSuBlake, it was just a stupid "return false;" missing Now it runs smoothly 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now