imakewebthings / waypoints

Waypoints is a library that makes it easy to execute a function whenever you scroll to an element.
http://imakewebthings.com/waypoints/
10.38k stars 1.33k forks source link

Scroll to Waypoint? #610

Open tacman opened 4 years ago

tacman commented 4 years ago

Thanks, Caleb, for putting this library together, it's really great.

How can I programmatically scroll to a waypoint? I'm highlighting the text in the middle of the screen

$('.waypoint').each(function(index, element) {
    const waypoint = new Waypoint({
        element: element,
        offset: '50%', 
        handler: (e) => {
            let $el = $(this);
            let text = $el.first();
            $('.expand').removeClass('expand');

            // get the text span (dialogue) element
            let $dialogElement = $el.find('.dialogue-text').addClass('expand');
        });
});

I've been trying to use the jquery-scrollto plugin, but running into issues with webpack, so figured I'd ask here just in case there's an easy way to do it. You've obviously done a lot of work with the scrolling and positioning events.

Thanks.