Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Commit

Permalink
#1006 Improve requestAnimationFrame performance (v1.0).
Browse files Browse the repository at this point in the history
  • Loading branch information
pazguille committed Oct 28, 2013
1 parent 21ec94a commit 52f643a
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions src/shared/js/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@
};
}());

$window
.on(ch.onresize + '.viewport', function () { resized = true; })
.on(ch.onscroll + '.viewport', function () { scrolled = true; });

function update() {
// No changing, exit
if (!resized && !scrolled) { return; }

var eve = resized ? ch.onresize : ch.onscroll;
console.log('yay');

// Refresh viewport
this.refresh();
Expand Down Expand Up @@ -87,14 +82,37 @@
* @memberof! ch.viewport#element
* @type {(jQuerySelector | ZeptoSelector)}
*/
that.$el = $window;
this.$el = $window;

that.refresh();
this.refresh();

(function updateFrame() {
requestAnimFrame(updateFrame);
update.call(that);
}());
$window
.on(ch.onresize + '.viewport', function () {
// No changing, exit
if (!resized) {
resized = true;

/**
* requestAnimationFrame
*/
requestAnimFrame(function updateResize() {
update.call(that);
});
}
})
.on(ch.onscroll + '.viewport', function () {
// No changing, exit
if (!scrolled) {
scrolled = true;

/**
* requestAnimationFrame
*/
requestAnimFrame(function updateScroll() {
update.call(that);
});
}
});
};

/**
Expand Down

0 comments on commit 52f643a

Please sign in to comment.