Last active
October 22, 2015 01:02
-
-
Save chadhietala/023e74978381befaf8a7 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Controller.extend({ | |
| data: Ember.computed(function() { | |
| let arr = []; | |
| let i = 0; | |
| while (i < 100) { | |
| arr.push(i); | |
| i++; | |
| } | |
| return arr; | |
| }), | |
| showImages: true, | |
| actions: { | |
| toggleImages() { | |
| this.toggleProperty('showImages'); | |
| } | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Ember from 'ember'; | |
| export default Ember.Helper.extend({ | |
| init() { | |
| this._super(...arguments); | |
| this._animationFrame = null; | |
| this.img = new Image(); | |
| this.img.style.visibility = 'hidden' | |
| this.srcUrl = null; | |
| }, | |
| startScrollCheck() { | |
| const component = this; | |
| function step() { | |
| var continueStep = component.scrollCheck(); | |
| if (continueStep) { | |
| nextStep(); | |
| } | |
| } | |
| function nextStep() { | |
| component._animationFrame = requestAnimationFrame(step); | |
| } | |
| nextStep(); | |
| }, | |
| cancelScrollCheck() { | |
| if (this._animationFrame) { | |
| cancelAnimationFrame(this._animationFrame); | |
| this._animationFrame = undefined; | |
| } | |
| }, | |
| willDestroy() { | |
| this.cancelScrollCheck(); | |
| }, | |
| scrollCheck() { | |
| let { top, left, width, height } = this.img.getBoundingClientRect(); | |
| let clientHeight = document.documentElement.clientHeight; | |
| let clientWidth = document.documentElement.clientWidth; | |
| let clientX = 0; | |
| let clientY = 0; | |
| if (left < clientX + clientWidth && | |
| left + width > clientX && | |
| top < clientY + clientHeight && | |
| height + top > clientY) { | |
| this.img.src = this.srcUrl; | |
| this.img.style.visibility = 'visible'; | |
| return false; | |
| } | |
| return true; | |
| }, | |
| compute([srcUrl], { height = 100, width = 100 }) { | |
| this.srcUrl = srcUrl; | |
| this.img.height = height; | |
| this.img.width = width; | |
| this.startScrollCheck(); | |
| return this.img; | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "version": "0.4.13", | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js", | |
| "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
| "ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment