我正在使用 slimScroll jQuery plugin并且 destroy 选项似乎并没有完全破坏站点上的插件效果。
例如,如果您尝试销毁插件,然后滚动到之前可滚动的内容,则站点滚动功能将停止工作。您将能够使用滚动条滚动,而不是使用鼠标滚轮/触控板。
Here's a reproduction of the bug
注意几件事:
- 使用鼠标滚轮/触控板在先前可滚动的元素上滚动会阻止滚动。
- 在先前可滚动的元素之外滚动按预期工作。
- 如果您在销毁 slimScroll 之前将它滚动到底部,那么在销毁它时,它会在任何情况下正常工作。
我已经reported it in the repository ,但没有给出答案。它似乎被遗弃了。 我试过 different建议solutions , 但它们都不能正常工作。
问题似乎是缺少销毁插件的正确方法...
在 jsfiddle 中使用的代码:
$('.scrollable').slimScroll({
allowPageScroll: true,
height: '250px',
size: '10px',
alwaysVisible: true
});
$('.destroy').click(function(){
$('.scrollable').slimScroll({
destroy:true
});
});
最佳答案
问题是插件没有删除注册的事件。这应该可以解决问题:
$('.destroy').click(function(){
$('.scrollable').slimScroll({
destroy:true
});
var $elem = $('.scrollable'),
events = jQuery._data( $elem[0], "events" );
if (events) {
jQuery._removeData( $elem[0], "events" );
}
});
关于javascript - slimScroll destroy 不会取消绑定(bind)滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26783076/