Snap.svg
Snap.svg copied to clipboard
Adding load callback to Paper.image()
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
+1
+1