-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_item.js
47 lines (37 loc) · 1.02 KB
/
list_item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(function(CL){
var RenderLayer = CL.RenderLayer;
var CanvasImage = CL.CanvasImage;
var CanvasText = CL.CanvasText;
function ListItem(opt){
if(!(this instanceof ListItem)){
return new ListItem(opt);
}
this.init(opt);
};
ListItem.prototype = Object.create(RenderLayer.prototype);
ListItem.prototype.constructor = RenderLayer;
$.extend(ListItem.prototype,{
init:function(opt){
RenderLayer.prototype.init.apply(this,arguments);
},
isOutOfView:function(){
var parent = this.parent;
return this.drawTop + this.drawHeight < parent.scrollTop || this.drawTop > parent.scrollTop + parent.drawHeight;
},
update:function(){
//不在可视范围内的不update
if(this.isOutOfView()){
return;
}
RenderLayer.prototype.update.apply(this,arguments);
},
draw:function(){
//不在可视范围内的不绘制
if(this.isOutOfView()){
return;
}
RenderLayer.prototype.draw.apply(this,arguments);
}
});
CL.ListItem = ListItem;
})(window.CanvasList = window.CanvasList || {});