Snap.svg icon indicating copy to clipboard operation
Snap.svg copied to clipboard

Adding load callback to Paper.image()

Open matthewsimo opened this issue 10 years ago • 2 comments

Hi, I was using Snap.svg for a project recently and needed to bind to the load event of an image. I was doing this by creating me image via Paper.image() and using addEventListener('load', function(){ ... }); on the node from the returned Snap.svg element.

However, IE doesn't fire load events properly if it's dealing with a cached image. If it sees a src of a cached image it just ignores it and immediately loads without firing anything...

The fix, to be able to get load events in all browsers (ie9+), is to bind the load event to the image element before a src is applied, however this isn't possible with the current implementation of Paper.image() since it creates and applies src in it's call.

Was wondering if you would be interested in merging this feature in? I didn't want to bother filling out CLA & doing pull request if this wasn't deemed useful.

The fix would essentially change

Paper.image(src, x, y, width, height);

// to

Paper.image(src, x, y, width, height, cb);

It would bind the cb, to the load event, if it existed, after it got back the element from make().

Thoughts?

Thanks, Matthew

matthewsimo avatar Apr 02 '14 22:04 matthewsimo

+1

jpodpro avatar Nov 02 '17 02:11 jpodpro

+1

chadsaun avatar Jan 16 '18 00:01 chadsaun