Events » Image events

Image events

The onImageLoaded event will notify when an image is loaded and ready to display so that you can take actions such as fading it in, for example. Naturally, you’ll use this only on images that are downloaded from the internet.

There’s also onImageLoadError, which gets triggered when the image could not load for some reason (not found, a server error, wrong domain name,…).

Image events
onImageLoadedThe image is loaded and ready for display.
onImageLoadErrorThe image could not be loaded or downloaded.

Be sure to attach these events to the layer before settings its image property, otherwise, the image might have already loaded (even from an online source).

Image events example

The prototype below creates an imageLayer

# A layer, empty for now
imageLayer = new Layer
    size: 600
    borderRadius: 10
    opacity: 0

…attaches the events…

# The image loaded successfully
imageLayer.onImageLoaded ->
    label.html = "Done !"
    Utils.delay 1, ->
            opacity: 1
            opacity: 0
                time: 3
# Something went wrong
imageLayer.onImageLoadError ->
    label.html = "Image loading error"

…and only then loads an image from

# Loading a large image (1200 x 1200 pixels)
imageLayer.image = ""
Download Framer project

Once the image downloaded, the “Loading…” text will change to “Done !”, and the image will fade in while the text label fades out.

Tip: You can change to something like to see what happens when onImageLoadError gets triggered.

Image events example
onImageLoaded changes the label text to “Done !” and lets the image fade in