最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Skrollr: pass a function when the scroll position is after the last keyframe - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论