admin管理员组

文章数量:1390456

Skrollr is an awesome plugin, plenty of options, but I can't really understand if there's some method for passing a function when the scroll position is after the last keyframe. For example, take a look at this fiddle.

When you scroll the top 100 pixels, the scrollable-between class changes in scrollable-after. In a similar way I'd like to pass a function (ex: when the scroll position is after the last keyframe do stuff).

How would you achieve that?

Skrollr is an awesome plugin, plenty of options, but I can't really understand if there's some method for passing a function when the scroll position is after the last keyframe. For example, take a look at this fiddle.

When you scroll the top 100 pixels, the scrollable-between class changes in scrollable-after. In a similar way I'd like to pass a function (ex: when the scroll position is after the last keyframe do stuff).

How would you achieve that?

Share Improve this question asked Dec 3, 2013 at 15:15 user1861373user1861373 851 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You'll want to use the render option. Something like the following:

var box = $('#box'),
    boxDone = false;
skrollr.init({
    forceHeight: false,
    smoothScrolling: false,
    render: function() {
        if ( box.hasClass('skrollable-after') ) {
            if ( ! boxDone ) {
                boxDone = true;
               // do stuff
            }
        } else if ( boxDone ) {
            boxDone = false;
        }
    }
});

You don't necessarily have to have the boxDone variable, but it keeps it from running multiple times when that happens. You could also make it only happen once by not reseting that variable.

FIDDLE

I should probably also mention that you'll want make sure that whatever you do in there should run really fast or you run the risk of slowing down how smoothly everything moves. You might be able to get around that by using setTimeout, but I haven't done any testing with that.

本文标签: javascriptSkrollr pass a function when the scroll position is after the last keyframeStack Overflow