Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
84
rated 0 times [  90] [ 6]  / answers: 1 / hits: 98231  / 11 Years ago, fri, july 26, 2013, 12:00:00

I have images looking like <img ng-src=dynamically inserted url/>. When a single image is loaded, I need to apply iScroll refresh() method so that to make image scrollable.



What is the best way to know when an image is fully loaded to run some callback?


More From » html

 Answers
60

Here is an example how to call image onload http://jsfiddle.net/2CsfZ/2/



Basic idea is create a directive and add it as attribute to img tag.



JS:



app.directive('imageonload', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.bind('load', function() {
alert('image is loaded');
});
element.bind('error', function(){
alert('image could not be loaded');
});
}
};
});


HTML:



 <img ng-src={{src}} imageonload />

[#76717] Thursday, July 25, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;