0

I have next script. It works before img load, thou i use method load.

$(document).ready(function() {
  $('.slide-img img').load(function(){
    var height = $(this).height();
    var width = $(this).width();
    if (width > height) {
      $(this).attr('style', 'max-height: 100%');
    };
    if (height > width) {
      $(this).attr('style', 'max-width: 100%');
    };
  });
 });

how can i force script work after loading img?

1 Answers1

0

Use window.load method(jquery):

$(window).load(function() {
// this will fire after the entire page is loaded, including images
});

Or use window.onload method(javascript):

window.onload = function() {
// this will fire after the entire page is loaded, including images
};
Sumanta736
  • 695
  • 3
  • 10