js xRoll页面滚动位置插件升级版 支持触发和离开

正文开始

~~~ //addY 允许加多些像素作为侦听增加的高度 //滚动条监听事件 xRoll: function (el, addY, reachCallFunc, leaveCallFunc) { var this_ = { init: function (_el) { this_.listenScroll(_el); $(window).on("scroll", function () { this_.listenScroll(_el) }) }, listenScroll: function (_el) { $(_el).each(function () { var _self = $(this); var scroll_top = $(window).scrollTop(); var isWindowHeight = $(window).height(); if (scroll_top + isWindowHeight + addY > $(this).offset().top) { if (_self.attr('data-state') == 1) { return; } // console.log('scroll_top:', scroll_top, 'isWindowHeight', isWindowHeight, $(this), $(this).offset().top); reachCallFunc(_self); _self.attr("data-state", 1); } else { if (_self.attr('data-state') == 1) { if (leaveCallFunc) { leaveCallFunc(_self); } // console.log(scroll_top + isWindowHeight, $(this).offset().top); _self.attr('data-state', 0); } } }) } }; this_.init(el); }, ~~~ 演示:[/upload/post_files/EjRNNVIj5GOZMzFE.html](/upload/post_files/EjRNNVIj5GOZMzFE.html)

正文结束

js 正则替换返回值做回调函数 安装gulp4