有两个绑定到$(window).scroll()
的js脚本。在一个脚本(example1.js)中,当满足某些条件时,我需要解除绑定事件(或找到可接受的替代方案),但这会导致事件完全解除绑定,并删除所有功能。解除绑定多次的事件
我想要做的是,一旦符合标准,停止滚动事件从example1.js的发射而不是example2.js。
example1.js
function exampleFunction(self) {
$(window).scroll(function() {
if ($(window).scrollTop() >= $(document).height() - $(window).height() - 364) {
self.start();
}
});
$.ajax({
url: self.settings.dataUrl,
dataType: "json",
async: false,
cache: false,
success: function (json) {
if (json.data.length) {
self.json = json;
self.addImages();
} else {
$(window).unbind('scroll');
}
}
});
}
example2.js
$(window).scroll(function() {
someFunction();
});
非常好,正是我所需要的。谢谢! – bflemi3
@ bflemi3太好了!很高兴我能帮上忙。 – dSquared