jScrollPane - 绑定到事件会添加到所有实例
http://jscrollpane.kelvinluck.com/events.html
在此示例中,jscrollpane 使用类选择器将功能绑定到事件。我似乎无法只绑定到一个对象:
var pane = $('#scrollable');
pane.bind(
'jsp-scroll-y',
function (event, scrollPositionY, isAtTop, isAtBottom) {
if (isAtBottom) {
$('#navigation').addClass('hiddenAtBottom');
} else {
$('#navigation').removeClass('hiddenAtBottom');
}
if (isAtTop) {
$('#lioverview a').addClass('focus');
} else {
$('#lioverview a').removeClass('focus');
}
$('.content').each(function (i) {
var ob = $(this);
var offSet = ob.offset();
var newOffset = (offSet.top - 150);
if (newOffset <= 0) {
$('#navigation a').removeClass('focus');
$('#navigation li:eq(' + i + ') a').addClass('focus');
}
});
}
);
pane.jScrollPane({
animateScroll: true,
animateDuration: 2500,
animateEase: '',
hijackInternalLinks: true
});
按预期工作。如果添加另一个我不希望上面绑定的可滚动区域,我会认为我创建了另一个实例(和一个单独的对象),
就像它一样简单
$('.accScrollable').jScrollPane();
,滚动条出现,但每次我滚动到这些元素的底部,另一个绑定函数被触发!
有人知道这里发生了什么事吗?
问候
http://jscrollpane.kelvinluck.com/events.html
In this example jscrollpane uses a class selector to bind functionality to the events. I cannot seem to bind to only one object:
var pane = $('#scrollable');
pane.bind(
'jsp-scroll-y',
function (event, scrollPositionY, isAtTop, isAtBottom) {
if (isAtBottom) {
$('#navigation').addClass('hiddenAtBottom');
} else {
$('#navigation').removeClass('hiddenAtBottom');
}
if (isAtTop) {
$('#lioverview a').addClass('focus');
} else {
$('#lioverview a').removeClass('focus');
}
$('.content').each(function (i) {
var ob = $(this);
var offSet = ob.offset();
var newOffset = (offSet.top - 150);
if (newOffset <= 0) {
$('#navigation a').removeClass('focus');
$('#navigation li:eq(' + i + ') a').addClass('focus');
}
});
}
);
pane.jScrollPane({
animateScroll: true,
animateDuration: 2500,
animateEase: '',
hijackInternalLinks: true
});
works as intended. If a add another scrollable area which I dont want the above to be bound to, I would think that I create another instance (and a seperate object)
something simple like
$('.accScrollable').jScrollPane();
Which, the scrollbars appear but every time I scroll to the bottom of these elements, the other bound function fires!
anyone know whats going on here?
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来你所描述的是一个错误,所以我只是整理了一个简单的例子来测试。你可以在这里看到它:
http://jsfiddle.net/qSf2q/1/
这是 javascript代码:
如果您滚动#pane1,您将收到包含#pane1 的控制台消息,如果您滚动#pane2,您将收到以#pane2 开头的消息。
所以看起来这个错误是在你的代码中,而不是在 jScrollPane 中。由于您没有包含完整的代码或指向它的链接,我们无法真正提供帮助,但希望这个示例向您展示如何将侦听器绑定到不同的 DOM 元素...
It sounded like what you were describing was a bug so I just put together a simple example to test. You can see it here:
http://jsfiddle.net/qSf2q/1/
Here is the javascript code:
If you scroll #pane1 you will get the console message with #pane1 in it and if you scroll #pane2 you will get the message which starts with #pane2.
So it seems that the bug is with your code and not with jScrollPane. Since you don't include the whole code or a link to it we can't really help but hopefully this example shows you how you can bind listeners to different DOM elements...
jsp-scroll-y
的事件处理程序会影响与绑定元素this
没有牢固关系的元素,在本例中是#scrollable
。您的 HTML 是否包含多个
#navigation
、#lioverview
或.content
?Your event handler for
jsp-scroll-y
affects elements without a solid relation to the bound elementthis
, in this case#scrollable
.Does you HTML contain multiple
#navigation
,#lioverview
or.content
?