只需向iScroll 选项添加另一个选项,如下所示:
var myScroll = new iScroll('wrapper', {
bounce: true,
onScrollEnd: function(e) {
if (this.y == this.minScrollY)
alert('This is the beginning');
if (this.y == this.maxScrollY)
alert('This is the end');
}
});
我在这里使用了onScrollEnd 事件,但您可以从多个中进行选择,例如 these。
你可以找到工作的 jsFiddle HERE。
更新
要准确地向您展示什么是可能的,您可以执行以下操作:
HTML
<div id="begin"><b>The START</b></div>
<div id="end"><b>The END</b></div>
CSS
#begin {
height:80px;
padding: 3px;
position:absolute;
top:150px;
}
#end {
height:80px;
padding: 3px;
position:absolute;
top:150px;
display:none;
}
JavaScript
function loaded() {
var myScroll = new iScroll('wrapper', {
bounce: true,
onScrollEnd: function(e) {
if (this.y == this.minScrollY)
$("#begin").show();
if (this.y < this.minScrollY)
$("#begin").hide();
if (this.y == this.maxScrollY)
$("#end").show();
if (this.y > this.maxScrollY)
$("#end").hide();
}
});
}
$(document).ready(function(){
loaded();
});
div 出现在开头和结尾处。
你可以找到这个实现的演示HERE
更新:iScroll5
对于 iScroll 5,您执行以下操作:
var myScroll;
function loaded () {
myScroll = new IScroll('#wrapper', {
scrollbars: true,
interactiveScrollbars: true,
mouseWheel: true,
fadeScrollbars: false
});
myScroll.on('scrollEnd', function() {
if (this.y == 0)
$("#begin").show();
if (this.y < 0)
$("#begin").hide();
if (this.y == this.maxScrollY)
$("#end").show();
if (this.y > this.maxScrollY)
$("#end").hide();
});
}
loaded();
您还要确保遵守新的语法和 CSS 规范。
您可以找到其中的一些HERE。
或者你可以定义一个边距(也许这适用于魔术鼠标)