johnpolacek / superscrollorama

The original jQuery plugin for supercool scroll animation. NOTE: No longer under active development. New version is ScrollMagic.js
http://johnpolacek.github.com/superscrollorama/
2.39k stars 539 forks source link

How do I use scrollTo in scrollorama in pinned elements? #109

Closed abhisuri97 closed 10 years ago

abhisuri97 commented 10 years ago

The way i plan to have my page set up is in the following way. The Timeline lite title (as shown in the demo). Where the credits of the title slide are, there will be a button that says "click to scroll down" That will move into the first pinned element. Each pinned element will have a "Next" button on it which will make the page scroll to move to the next pinned element. I have tried looking on the GSAP forums and they weren't really a help since I am rather inexperienced with JavaScript. I was wondering if anyone would be able to help me on this. additionally I have tried using what the following page recommended http://codeaway.info/greensock-animation-platform-scroll-to-plugin-sample/ and it worked in every browser except safari.

janpaepke commented 10 years ago

Hi!

Actually you were correct to go to the TweenMax Forums, as this really isn't a superscrollorama issue. But as I personally have a thing against newbie haters I'll try to help you.

Firstly I would strongly recommend setting pushFollowers to false, so you'll have the correct positions of all pinned elements right from the start. Bare in mind that his might require you to set your own spacers. For detailed descriptions see issue https://github.com/johnpolacek/superscrollorama/issues/93 .

Secondly I would add an anchor element at the top position of each pin element. This should be the point where you want to scroll when clicking the "next" link. Try out this setup by using anchors <a name="myanchor"></a> and then have Buttons like <a href="#myanchor">next</a>. When you click the link the page should now jump to the correct position. Now you don't want it to jump, but scroll instead, right?

So here's how you do it:

$(document).ready(function() {
    // page internal links
    $('a[href^="#"]').click(function (e) {
        var anchor = $(this).attr("href").substr(1);
        var $target = $('a[name="' + anchor + '"]').first();
        if ($target.length > 0) {
            e.preventDefault();
            var scrollYPos = $target.offset().top;
            TweenLite.to(window, .7, {scrollTo:{y:scrollYPos, x:0}, ease:Power2.easeOut});
        }
    });
});

Bear in mind, that the ScrollTo plugin is not loaded by default. You will have to include the javascript file. You can do it right after you include the main TweenMax file.

Please try not only to copy and paste the code (I have not tested it and it may not work). Try to understand what I did and redo it line by line. This way you'll learn.

regards, J

abhisuri97 commented 10 years ago

I just tried your solution and it worked great. except in safari where the scrolldown animation would stop midway. in chrome and firefox it worked (I haven't tested IE yet). Do you have any suggestions about safari?

janpaepke commented 10 years ago

Hi!

What greensock version are you using? There seem to have been problems in older versions: http://forums.greensock.com/topic/7205-scrollto-bug-in-182-in-safari-602-mountain-lion/

If you're using a current version I'd like you to figure out wether it is a superscrollorama issue. Please disable all superscrollorama scripts and try clicking the links. If the bug still appears this is definitely a TweenMax Problem and we can't help you any further...

regards, J

janpaepke commented 10 years ago

By the way a "thank you" might have been nice...

abhisuri97 commented 10 years ago

First of all, thank you for all the effort you have put in so far. I have finally put up the website at the following address http://www.appsforaptitude.org/learnhtml/index.html I have updated my scrollTo plugin, and made sure the problem was in scrollorama. Once again, things work fine in every browser except safari (it may work the first or second time, but after that it will just stop midway through scrolling). Is there another script I can use to accomplish the goal of scrolling?

jkrot commented 10 years ago

I took a short look at it yesterday, think the issue maybe on the jquery side, will play around with it today to confirm. On Oct 27, 2013 3:03 AM, "webfreak7" notifications@github.com wrote:

First of all, thank you for all the effort you have put in so far. I have finally put up the website at the following address http://www.appsforaptitude.org/learnhtml/index.html I have updated my scrollTo plugin, and made sure the problem was in scrollorama. Once again, things work fine in every browser except safari (it may work the first or second time, but after that it will just stop midway through scrolling). Is there another script I can use to accomplish the goal of scrolling?

— Reply to this email directly or view it on GitHubhttps://github.com/johnpolacek/superscrollorama/issues/109#issuecomment-27164768 .

abhisuri97 commented 10 years ago

I have also made a repo containing the website files here. https://github.com/webfreak7/learnhtml2

abhisuri97 commented 10 years ago

UPDATE: I download the query.smooth-scroll.js plugin and everything works now! Thanks for all the help people.