Reputation:
i have this code:
var jq111 = jQuery.noConflict();
jq111('.slides img').each(function(){
jq111self = jq111(this).height();
if(jq111self < 500){
jq111(this).addClass( "product-rescue" );
}
});
if an image is less than 500 px apply a CSS class.
But there is a problem, is not working properly, and is applied 1/3 to images larger than 500px.
why?
https://jsfiddle.net/cuaqaxy8/3/
Upvotes: 0
Views: 85
Reputation: 3084
you need to wait for the image to load:
var jq111 = jQuery.noConflict();
jq111('.slides img').on("load", function() {
var jq111self = jq111(this);
if(jq111self.height() < 500){
jq111self.addClass("product-rescue");
}
});
Upvotes: 7