2012-04-13 7 views
1

Ich lade ein Bild und Anzeige, sobald das Bild fertig ist und verschiedene CSS und Animationen abgeschlossen sind. Aber ich möchte das Bild zur Überprüfung der Breite und Höhe innerhalb der Funktion aufrufen:Act auf Bild laden ohne zweimal laden

$('.ePage').find('img').each(function(){ 
    var $img = $(this); 
    $('<img/>').load(function(){ 

     // my css and animations 
     // need to check height and width 


    }).attr('src',$img.attr('src')); 
}); 

Nur ich möchte das Bild nicht zweimal laden. Wie kann ich das machen?

Antwort

1
$('.ePage').find('img').each(function(){ 
    var $img = $(this); 
    $('<img/>').load(function(){ 

     console.log($(this).css("width")); 
     console.log($(this).css("height")); 
     console.log($(this).width()); 
     console.log($(this).height()); 

    }).attr('src',$img.attr('src')); 
}); 
+0

Yep, scheint ich insgesamt mentale Blockade hatte. Ich warf die $ img.width() und $ img.height() nach einer Funktion, die die Höhe editierte. Zeit für eine Pause, denke ich. Danke für die Hilfe karim79 :) –