建站资源下载详情

为您免费提供多种建站资源下载,包括网站模板下载、前端插件下载和字体下载!您只需注册为会员即可任意下载!

JQuery页面滚动事件监听插件Waypoints

来源:易助科技网浏览量:68收藏

简介


Waypoints是一款用于捕获各种滚动事件的JQuery插件,同时它还支持固定元素和无限滚动的功能,功力十分强大。


JQuery页面滚动事件监听插件Waypoints-示例图



使用


1.  引入 jquery.js 和 waypoints.js 文件


2.  调用


最简单的使用方法是调用.waypoint,并传递到一个函数中


$('#example-basic').waypoint(function() {
  notify('Basic example callback triggered.');
});


这时会在#example-basic的顶部刚碰到用户视角的顶部时出现一个提示,callback会在你经过这点设定点触发,不管你是向上滚 动还是向下滚动. 大部分情况下我们想在用户向不同方向滚动时展现不同的动作。Waypoints将方向作为参数传递给回调函数


$('#example-direction').waypoint(function(direction) {
  notify('Direction example triggered scrolling ' + direction);
});


这里通知将表现为”Direction example triggered scrolling down”或者”Direction example triggered scrolling up”。如果你是想让waypoint在某个位置触发而不是你元素的顶部碰到视角的顶部怎么办?waypoint函数提供了第二种自变量选项对象。其中最有用的是offset,即告诉Waypoints要离开窗口顶部多远才触发,offset可以用像素来表示。


$('#example-offset-pixels').waypoint(function() {
  notify('100 pixels from the top');
}, { offset: 100 });


或者用比例来表


$('#example-offset-percent').waypoint(function() {
  notify('25% from the top');
}, { offset: '25%' });


或者是一个函数,这个函数需要返回一个数字


$('#example-offset-function').waypoint(function() {
  notify('Element bottom hit window top');
  }, {offset: function() { return -$(this).height(); }  
});



相关链接


官网地址 :  http://imakewebthings.com/waypoints/

官方文档 :  https://modrinth.com/plugin/waypoints/

Github 地址 :https://github.com/imakewebthings/jquery-waypoints