Jump to content
Search Community

scrollTop not working on ios

Johny13
Moderator Tag

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

Posted

Hi guys,

i have a problem when using scrollTop on ios phones that cant recognize. Is there a way to fix it? This is my code: 

        TweenMax.set('.trail-wrapper', { alpha: 0 })
        TweenMax.set('.cloud', { alpha: 0 })
        var tl = new TimelineMax({ paused: true });

        tl.to('.trail-wrapper', 0.5, { alpha: 1 })
            .to('.cloud', 0.5, { alpha: 1 })
            .to('.rocket-wrapper', 1.5, { y: -400, ease: Expo.easeIn })
            .to('.cloud', 2.5, { attr: { cy: 185 }, ease: Expo.easeIn }, "-=3")
            .set('.cloud', { clearProps: "all" })
            .set('.rocket-wrapper', { y: 0 })
            .to('body', 1, { scrollTop: 0, autoKill:false })
            .to('.rocket-wrapper', 4, { y: 0, ease: Elastic.easeOut.config(0.5, 0.4) })
            .to('.trail-wrapper', 2.5, { scaleX: 0.5, scaleY: 0, alpha: 0, ease: Expo.easeOut }, "-=2.0")

        $('.toTop').on('click', function () {
            tl.play(0)
        });

 

Posted

I think you need to use 'scrollTo'  with scrollTo plugin, and probably on window rather than body. Does your code work in other browsers?

 

.to(window, 1, { scrollTo: 0, autoKill:false })

 

  • Like 2
Posted

It won't work:

Uncaught TypeError: Failed to execute 'scrollTo' on 'Window': parameter 1 ('options') is not an object.

Posted

Can you post a codepen demo? It will be hard to guess without demo.

 

 

  • Like 1
Posted

Hi @Johny13

 

Are you sure the element you're targeting is actually scrollable? You can get the current scroll position of an element like this:

var body = document.querySelector('body');
console.log(body.scrollTop);

 

I tried adding a div parent with 'overflow:scroll' and set it as the scroll container in the tween, and it worked just fine as far as I could tell.

 

Edit: In Codepen it's the parent element of the body that gets the scrollbars.

  • Like 3
Posted

It is, it just needed to by inside quotation mark. Thanks for your help.

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...