2011-05-04 3 views
2

많은 사진을 표시하는 웹 사이트가 있습니다. 그것들을 보여주고로드하는 것을 보는 대신,로드가 끝나면 페이드 아웃하는 방법이 있습니까? jQuery와 javascript의 멋진 세상에 처음으로 등장했습니다.jQuery fadeIn이 완료되면 각 개별 DIV에 이미지가로드됩니까?

지금은 mySQL 서버를 호출하고 최신 이미지를 가져 오는 PHP 파일에서 데이터를 가져옵니다.

// If the user clicks the logo 
$("#logo").click(function() { 
$("#right_bar_wrapper").animate({ height: 'toggle', opacity: 'toggle' }, '200'); 
var thePostData = "username=c"; 
$.ajax({ 
    type: "POST", 
    url: "http://myflashpics.com/v2/process_newsfeed.php", 
    data: thePostData, 
    success: function(theRetrievedData) { 
    document.getElementById('right_bar_wrapper').innerHTML = theRetrievedData; 
    $("#right_bar_wrapper").fadeIn("200"); 

    } 
}); 
}); 

다음은 그 각각의 이미지가 들어있는 것처럼 ONE 사업부 보이는 내용은 다음과 같습니다 : 그것은 단지 HTML의 큰 블록을 표시하기 위해 반환

<div class='sidebar_image_box_newsfeed'> 
<div class='sidebar_image_box_newsfeed_user_info makeProfileAppear' id='user_coultonvento'><img src='http://myflashpics.com/get_image.php?short_string=kmdp&size=thumbnail' />TheAmazingCoultoniusTheFourneeth...</div> 
<img src='http://myflashpics.com/get_image.php?short_string=6v9o&size=big' id='image_6v9o' class='makePictureBig' style='width: 180px;' /> 
<div class='sidebar_image_box_newsfeed_user_info_comments' style='float: right; margin-top: -1px; margin-left: 20px; display: none;' id='bigpicture_comment_6v9o'>9</div> 
<div class='sidebar_image_box_newsfeed_caption'>Usama bin laden? I believe that's a typo, Fox. </div> 
<div class='sidebar_image_box_newsfeed_user_info_comments' id='littlepicture_comment_6v9o'>9</div> 
<div style='clear: both;'></div> 
</div><div class='sidebar_image_box_newsfeed'> 
<div class='sidebar_image_box_newsfeed_user_info makeProfileAppear' id='user_BrandonVento'><img src='http://myflashpics.com/get_image.php?short_string=e4r7&size=thumbnail' />Brandon Vento</div> 
<img src='http://myflashpics.com/get_image.php?short_string=o1sk&size=big' id='image_o1sk' class='makePictureBig' style='width: 180px;' /> 
<div class='sidebar_image_box_newsfeed_user_info_comments' style='float: right; margin-top: -1px; margin-left: 20px; display: none;' id='bigpicture_comment_o1sk'>9</div> 
<div class='sidebar_image_box_newsfeed_caption'></div> 
<div class='sidebar_image_box_newsfeed_user_info_comments' id='littlepicture_comment_o1sk'>9</div> 
<div style='clear: both;'></div> 
</div> 

물론, 그것은 페이드하지만 사용자가로드 본다.

이 작업을 수행하는 가장 좋은 방법은 무엇입니까?

감사합니다,
Coulton

+0

에서 봐? – Nick

+0

@ 닉 : 이미지로드를 감시하십시오. Google 크롬에서는 이미지의 상단이 보이고 나머지 이미지는 천천히 보입니다. 로드 될 때까지 숨어서 페이드 인하는 것은 어떨까요? – iosfreak

답변

2

로드 이벤트 D fadeIn()에 결합하는 동적 IMG 요소

+0

+1하지만 첫 fadeIn을 잊어 버렸습니다. – Andre

+0

아 그렇습니다 :) 댓글을 주셔서 감사합니다. 아주 좋습니다. Coulton, 알지? 앙드레가 말한 것. –

2

로드 스타일로 IMG 태그 = '표시 : 없음'과 결합 문서에 그것을 페이드 이미지의 부하() 이벤트 :. http://api.jquery.com/load-event/

샘플 :

대신 AJAX의
$(".makePictureBig").live('load', function(){ 
    $(this).fadeIn(); 
}); 
+0

여러 이미지가있는 경우 어떻게해야합니까? 나는 개인적으로 각자를 퇴색시키고 싶지 않다. – iosfreak

+0

각 이미지가로드 된 후에 load()가 개별적으로 호출됩니다. – ariel

+0

이미지가로드 될 때 호출되지 않습니다. 'alert();'을 넣으면 결코 나타나지 않습니다. 가능한 문제가 무엇일까요? 특정 라이브러리가 있습니까? – iosfreak

1

퍼스를 사용 .load()는 부하() 함수, 빈의 콜백과 같이, 그런

를 사용하여 간단로서 만약

$.ajax({ 
    type: "POST", 
    url: "http://myflashpics.com/v2/process_newsfeed.php", 
    data: thePostData, 
    success: function(theRetrievedData) { 
    document.getElementById('right_bar_wrapper').innerHTML = theRetrievedData; 
    $("#right_bar_wrapper").fadeIn("200"); 
    //here do some trick 
    $("#right_bar_wrapper img").load(function(){ 
     $(this).fadeIn(); 
    }); 
    } 
}); 

또는 라이브 사용할 수 있도록 할 JQuery와 화상 .load() 함수를 사용할 수

$("#logo").click(function() { 
    $("#right_bar_wrapper") 
    .animate({ height: 'toggle', opacity: 'toggle' }, '200') 
    .load("http://myflashpics.com/v2/process_newsfeed.php", 
      {"username" : "c"}, 
      function() { 
       $(this).bind('load',function(){ 
        $(this).fadeIn("200"); 
       }); 
      } 
); 
}); 
+0

흠 .. 작동하지 않았어. 내 JS 아무도 작동하지 않습니다 .. 어쩌면 문법과 문제가 무엇입니까? – iosfreak

+0

이미 추가 된 †가 있습니다. 지금 시도해보십시오, 작동하지 않으면 바이올렛을 제공하십시오 – Andre

+0

다시, 오타였습니다. 바인드 기능을 닫는 것을 잊었습니다. 이 문제가 이미 해결 되었기 때문에 기쁩니다. – Andre

관련 문제