Last active
October 1, 2015 18:59
-
-
Save AugustMiller/83655378a4ccaf758856 to your computer and use it in GitHub Desktop.
Image Load Notifier
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
| module.exports = class LazyLoad | |
| constructor: (@el, @callback) -> | |
| if @is_loaded() then @after() else @listen() | |
| listen: -> | |
| @el.on 'load', (e) => @after() | |
| is_loaded: -> | |
| @loaded = @el.get(0).complete | |
| after: -> | |
| @loaded = true | |
| @el.addClass 'loaded' | |
| @callback @el |
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
| Notifier = require 'image-notifier' | |
| $('img').each (index, el) -> | |
| Notifier $(el), (img) -> | |
| img.addClass 'loaded' | |
| # Or whatever else you want. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment