Skip to content

Instantly share code, notes, and snippets.

@poteto
Created April 17, 2015 22:22
Show Gist options
  • Save poteto/cc39d464955c82d82048 to your computer and use it in GitHub Desktop.
Save poteto/cc39d464955c82d82048 to your computer and use it in GitHub Desktop.
_setViewportEntered(context=null) {
Ember.assert('You must pass a valid context to _setViewportEntered', context);
const $viewportCachedEl = get(this, '$viewportCachedEl');
const viewportUseRAF = get(this, 'viewportUseRAF');
const elementId = get(this, 'elementId');
const tolerance = get(this, 'viewportTolerance');
const height = $(context) ? $(context).height() : 0;
const width = $(context) ? $(context).width() : 0;
let boundingClientRect;
if ($viewportCachedEl) {
boundingClientRect = $viewportCachedEl[0].getBoundingClientRect();
} else {
boundingClientRect = set(this, '$viewportCachedEl', this.$())[0].getBoundingClientRect();
}
const viewportEntered = isInViewport(boundingClientRect, height, width, tolerance);
set(this, 'viewportEntered', viewportEntered);
if ($viewportCachedEl && viewportUseRAF) {
rAFIDS[elementId] = window.requestAnimationFrame(
bind(this, this._setViewportEntered, context)
);
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment