Julien de Denaro
Julien de Denaro

Reputation: 43

jQuery(window) Ajax navigation

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 !

Upvotes: 1

Views: 193

Answers (3)

Julien de Denaro
Julien de Denaro

Reputation: 43

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();
    });

});

Upvotes: 0

Akhil Sekharan
Akhil Sekharan

Reputation: 12693

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

Upvotes: 1

Mike
Mike

Reputation: 118

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();
 }

Upvotes: 1

Related Questions