-
Notifications
You must be signed in to change notification settings - Fork 9
/
Scrollbar.js
36 lines (28 loc) · 1.11 KB
/
Scrollbar.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
var Scrollbar = pc.createScript('scrollbar');
Scrollbar.attributes.add('speed', { type : 'number', default : 0.035 });
Scrollbar.attributes.add('padding', { type : 'number', default : 30 });
Scrollbar.prototype.initialize = function() {
this.lastUpdate = Date.now();
this.percentage = 0;
this.entity.element.on('mousewheel', this.onWheel, this);
this.contentEntity = this.entity.findByName('Content');
};
Scrollbar.prototype.onWheel = function(data) {
if(data.event.deltaY > 0){
this.entity.scrollview.scroll.y =-this.speed;
}else{
this.entity.scrollview.scroll.y = 1 + this.speed;
}
};
Scrollbar.prototype.update = function(dt) {
if(Date.now() - this.lastUpdate > 1000 && this.contentEntity){
var totalHeight = 0;
var entities = this.contentEntity.children;
for(var entityIndex in entities){
var entity = entities[entityIndex];
totalHeight+=entity.element.calculatedHeight;
}
this.contentEntity.element.height = totalHeight + this.padding;
this.lastUpdate = Date.now();
}
};