Skip to content

Commit

Permalink
cache calculation values that were calculate on each scroll event to …
Browse files Browse the repository at this point in the history
…improve performances
  • Loading branch information
Adrien Grsmto committed Apr 17, 2017
1 parent 8a94e27 commit d2bf77f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,22 @@ export default class SimpleBar {
let scrollbar;
let scrollOffset;
let contentSize;
let scrollbarSize;

if (axis === 'x') {
track = this.trackX;
scrollbar = this.scrollbarX;
scrollOffset = this.contentEl[this.scrollOffsetAttr[axis]]; // Either scrollTop() or scrollLeft().
contentSize = this.contentEl[this.scrollSizeAttr[axis]];
contentSize = this.contentSizeX;
scrollbarSize = this.scrollbarXSize;
} else { // 'y'
track = this.trackY;
scrollbar = this.scrollbarY;
scrollOffset = this.scrollContentEl[this.scrollOffsetAttr[axis]]; // Either scrollTop() or scrollLeft().
contentSize = this.contentEl[this.scrollSizeAttr[axis]] - 15;
contentSize = this.contentSizeY;
scrollbarSize = this.scrollbarYSize;
}

let scrollbarSize = track[this.sizeAttr[axis]];
let scrollbarRatio = scrollbarSize / contentSize;
let scrollPourcent = scrollOffset / (contentSize - scrollbarSize);
// Calculate new height/position of drag handle.
Expand Down Expand Up @@ -435,6 +437,11 @@ export default class SimpleBar {
* Recalculate scrollbar
*/
recalculate() {
this.contentSizeX = this.contentEl[this.scrollSizeAttr['x']];
this.contentSizeY = this.contentEl[this.scrollSizeAttr['y']] - (this.scrollbarWidth || this.offsetSize);
this.scrollbarXSize = this.trackX[this.sizeAttr['x']];
this.scrollbarYSize = this.trackY[this.sizeAttr['y']];

this.resizeScrollbar('x');
this.resizeScrollbar('y');

Expand Down

0 comments on commit d2bf77f

Please sign in to comment.