Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
Last active October 1, 2015 18:59
Show Gist options
  • Save AugustMiller/83655378a4ccaf758856 to your computer and use it in GitHub Desktop.
Save AugustMiller/83655378a4ccaf758856 to your computer and use it in GitHub Desktop.
Image Load Notifier
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
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