我有一个无限的scroll类:
(function(){
"use strict";
var InfiniteScroll = function() {
this.init();
};
var p = InfiniteScroll.prototype = mc.BaseClass.extend(gd.BaseClass);
p.BaseClass_init = p.init;
/*
* Public properties
*/
p.loading = false;
/*
* Public methods
*/
p.init = function() {
// Super
this.BaseClass_init();
// Init
this.ready();
};
p.ready = function() {
this._initInfiniteScroll();
};
p._initInfiniteScroll = function() {
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
if(!p.loading)
{
p.loading = true;
//send a message up to say loading
}
}
});
}
mc.InfiniteScroll = InfiniteScroll;
}(window));现在这是从另一个类调用的:
this.infiniteScroll = new mc.InfiniteScroll();在另一个类中,我希望监听何时从我有注释的地方触发滚动://发送一条消息,表示正在加载
我只是想知道我该怎么做,我对AS3中的事件侦听器很熟悉,但是有人能为我指出js的正确方向吗?
发布于 2014-02-06 18:51:04
您可以在类中实现自定义事件处理程序,并在其上添加其他类中的侦听器函数,如在this post中。
您将在_initInfiniteScroll函数中使用它,如下所示:
//send a message up to say loading
this.fire({ type: "ContentLoadingEvent" });不过,正如文章中所建议的,为你的InfiniteScroll事件创建一个单独的类更好。
https://stackoverflow.com/questions/21600449
复制相似问题