有兩個綁定到$(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