Search code examples
jquerygsap

Is there a way to use GSAP's scrollToPlugin to scroll to a div ID?


In the documentation, it lists a variety of ways to use the plugin but they all seem to require a number to input (e.g. "scrollTo:{y:250}"). I'm wondering if, instead of a number, there is a way to input a div id.

jQuery(document).ready(function($){

    $('.full-streams-link').on('click', 'a', function(e) {
        e.preventDefault();

        TweenLite.to(window, .4, {
            scrollTo: {y:500},
            ease: Power2.easeOut,
            force3D: true
        });

    });

});

Solution

  • For the y value, you can pass in the position top:

    You could do

    y: $('#element').position().top