How to use Twitter Bootstrap ScrollSpy to execute a function

前端 未结 3 792
太阳男子
太阳男子 2021-01-05 15:10

I would like to load more data after ScrollSpy receives notification. But I don\'t see how to capture that event and execute a function.

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 15:47

    This is for Bootstrap 4 (beta 3):
    In general, the usage of the Scrollspy event did not change from Bootstrap 3. As it is stated at the Events section of the Scrollspy documentation, the activate.bs.scrollspy event will be fired on the scroll element –the one with data-spy="scroll"– whenever a new item becomes activated by the Scrollspy. You can listen to it like that:

    $('[data-spy="scroll"]').on('activate.bs.scrollspy', function(event) {
        console.log('activate.bs.scrollspy', event);
    })
    

    But!
    It is not documented, that when the Scrollspy is used on the element, the activate.bs.scrollspy event will be available only on the window object.
    So, in this rather common case, you can catch the Scrollspy event like so:

    $(window).on('activate.bs.scrollspy', function (event) {
        console.log('activate.bs.scrollspy', event);
    })
    

提交回复
热议问题