0

jquery .loadを介していくつかのhtmlコンテンツを動的にロードしています。すべてのコンテンツがロードされていることを確認するのに苦労しています。テキストの動的な読み込みはうまくいっているようです。私が問題を抱えているのは、html コンテンツの読み込みです。

これはページです。左下の画像の青い盾をクリックすると、高さいっぱいまでアニメーション化されていないことがわかります http://www.klossal.com/しかし、ここを見ると、どのように読み込まれるかがわかります動的にロードされないため動作します http://www.klossal.com/index_backup.html

これは、html をロードするスクリプトの一部です。

$('#images').load(id +".html", function() {

console.log('Loaded'); //Testing Purposes Only
IMG=1; // Loaded
animate_section(); // Attempt Animation 


});

これはスクリプト全体です。

var a1, a2, a3, a4, IMG;

$(".thumb_container_site").click(function() {

a1=0; //Reset the Loading Variables
a2=0;
a3=0;
a4=0;
IMG=0;

var id = $(this).attr('id');

$('#images').load(id +".html", function() {

console.log('Loaded'); //Testing Purposes Only
IMG=1; // Loaded
animate_section(); // Attempt Animation 


});

$("#info_header").load(id +"_header.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a1=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_1").load(id +"_1.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a2=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_2").load(id +"_2.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a3=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_3").load(id +"_3.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a4=1; // Loaded
animate_section(); // Attempt Animation         

});


});

これについて私が得ることができるどんな助けも素晴らしいでしょう、ありがとう。

アニメーション機能はこちら

function animate_section() {

if((a1===1) && (a2===1) && (a3===1) && (a4===1) && (IMG===1)){ //Animate if all thre divs are loaded

$("#top_section").animate({
    height: $("#load_container").outerHeight(true) + 30
}, 300);
$("#grid").animate({
    marginTop: $("#load_container").outerHeight(true) + 300,
    paddingBottom: 300
}, 300);   
}                
}

わずかに異なる読み込み構造のための 2 番目の関数もありますが、これで何かが壊れるとは思いません。この関数は左上のサムネイル コンテンツをロードし、完全に右にロードします。

$(".thumb_container_img").click(function() {

a1=0; //Reset the Loading Variables
a2=0;
a3=0;
a4=0;
IMG=0;

var id = $(this).attr('id');


$('#images').empty();



$("<img>", { src: 'http://www.klossal.com/' + id + ".png" }).load(function () {    
$(this).prependTo("#images"), IMG=1 });

$("#info_header").load(id +"_header.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a1=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_1").load(id +"_1.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a2=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_2").load(id +"_2.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a3=1; // Loaded
animate_section(); // Attempt Animation         

});

$("#content_3").load(id +"_3.txt", function() {

console.log('Loaded'); //Testing Purposes Only
a4=1; // Loaded
animate_section(); // Attempt Animation         

});



});
4

1 に答える 1

0

画像自体が読み込まれたときではなく、テキスト ファイルが読み込まれたときに読み込みコールバックがトリガーされているように見えます。したがって、outerHeight() への呼び出しは、コンテナー要素の高さがその時点でイメージの読み込まれた部分と等しいため、正しくない値を取得しています。を入れて調査する必要があります

$('#load_container img').on('load', function(){
   //callback or emit an event that will listen and then respond with your callback
});
于 2012-11-24T02:53:37.127 に答える