Jump to content
Search Community

Draggable scroll: How to get current scroll position?

luneyard test
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

Hello,

 

I am trying to build a UI where two arrows – up and down – control the scroll position.

The scroll element is a Draggable.

var scroller = $('.scroller.draggable');

Draggable.create(scroller, {
        type:"scrollTop",
        edgeResistance:0.75,
        throwProps:true,
        onDragStart: function() {
            Draggable.get(menu).disable();
        },
        onDragEnd: function() {
            Draggable.get(menu).enable();
        }
    });

$('.icon-arrow-down').on('click', function(event){
        TweenLite.to(scroller, 1, {scrollTo:{y:$scope.yStart}, ease:Power2.easeOut, onComplete:updateYScroll});
        function updateYScroll() {
            console.log(this.scrollY);
            //$scope.yStart = scroller.scrollY + $scope.yIncrement;
        }
    });

But when calling scrollY I always get undefined...

 

Greetings,

luneyard

Link to comment
Share on other sites

Hello luneyard, and welcome to the GreenSock Forum!

 

I believe scrollY is only available on the window object.

 

Please see: https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY

 

I believe you are looking for using scrollTop instead:

 

Please see: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop

// Get the number of pixels scrolled
var  myScrollTop = this.scrollTop;
:

:)

  • Like 1
Link to comment
Share on other sites

Also note that you can check the Draggable's "y" property which is basically scrollTop in the opposite direction (so make it negative)

yourDraggable.y;

You can also use the methods on the scrollProxy of the Draggable as well:

yourDraggable.scrollProxy.scrollTop(); //returns the scroll position
  • Like 2
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...