1

I need to resize an image when I open a page. before ajax navigation, I used function jQuery(window) to say that I want to do my function resize when I get in my new page. But now with ajax navigationIi just load a part of my page so jQuery(window) returns nothing.

// start page KO PART
jQuery(window).load(function(){ 
    redimensionnement(); 
}); 
// KO PART END

// resize window OK --
jQuery(window).resize(function(){ 
    redimensionnement(); 
});

Do you have any idea to solve my problem?

Thanks a lot !

2
  • 2
    Can you not just call redimensionnement(); in the ajax callback? Nov 23, 2012 at 14:43
  • What do you mean by ajax navigation? Do you use an iframe that you control from a parent window or something else? Nov 23, 2012 at 14:45

3 Answers 3

1

On completion of your Ajax request load the image and when image is loaded than you resize images. here is sample code which might help you how to trace image loaded.

// create an image object
 objImage = new Image();

 // set what happens once the image has loaded 
objImage.onLoad=imagesLoaded(objImage);

 // preload the image file
 objImage.src='images/image1n.gif';

 // function invoked on image loaded
 function imagesLoaded(obj)
 {    
    var w = obj.width();
    var h = obj.height();
 }
1
  • Thanks a lot it is a good idea, but my image is heavy so I prefere to charge it when visitor enter in my image page. Nov 26, 2012 at 1:05
1

I think you need to bind it inside onload;

// start page KO PART
jQuery(window).load(function(){ 
    redimensionnement(); 
    // resize window OK --
        jQuery(window).resize(function(){ 
    redimensionnement(); 
    });
}); 
// KO PART END
1
  • I am sorry, my english is poor so I am not sure that I have clearly explain my problem. Nov 26, 2012 at 1:07
0

I have find the solution !

So, to resize my image when we enter in my image page, I test if it is load in my ajax loop like this :

   //ajax loop for full ajax navigation
   $.ajax({
   url: link,
   dataType:'html',
   success: function(data){

        //update of my contain
        var contenu = $(data).find("#contenu");
        $('#contenu').html(contenu).fadeIn('200');


        //TEST OF LOAD IMAGE, if yes, start my resize fonction
        $("#map-carte-1").load(function(){
       redimensionnement();
    });

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.