How to make jQuery waypoints plugin fire when an element is in view and not scrolled past?

前端 未结 4 1092
不思量自难忘°
不思量自难忘° 2020-12-16 13:34

Please see this:

http://jsfiddle.net/5Zs6F/2/

As you can see only when you scroll past the first red rectangle it turns blue, I would like it to turn blue th

4条回答
  •  北海茫月
    2020-12-16 13:58

    The offset option determines where in relation to the top of the viewport the waypoint should fire. By default it is 0, so your element fires when it hits the top. Because what you want is common, waypoints includes a simple alias for setting the offset to fire when the whole element comes into view.

    $('.box').waypoint(function() {
      $(this).css({
        borderColor: 'blue'
      });
    }, { offset: 'bottom-in-view' });
    

    If you want it to fire when any part of the element peeks in from the bottom, you should set it to '100%'.

提交回复
热议问题