2012-05-13 41 views
0

jqueryサイクルプラグインを使用してサムネイルで簡単なスライドショーを作成しています。画像の読み込み機能

http://www.ttmt.org.uk/forum/slideshow/

サムネイルは、ウィンドウの下部にとどまるスティッキーフッターにあります。

スライドショーイメージを残りのウィンドウに塗りたいと思っています。私は

function resizeImg() { 
    $('#slideshow img').css({'height':$('#wrap').height()-footerHeight,'width':'auto'}); 
} 

画像のサイズを変更するには、この関数を呼んでいるウィンドウのサイズ変更で

それがスペースを埋めていない場合、画像が最初にロード私の問題であり、それは元のサイズですされています。

イメージが読み込まれるときに、どのようにresizeImg関数を呼び出すことができますか。

<!DOCTYPE html> 
    <html> 
     <head> 
     <title>Title of the document</title> 
     <!--jQuery--> 
     <script type="text/javascript" src="js/jquery1.7.2.js"></script> 
     <script type="text/javascript" src="js/cycle.js"></script> 
     <!--CSS--> 

     <style type="text/css"> 
     *{ 
      margin:0; 
      padding:0; 
     } 
     ul{ 
      list-style:none; 
     } 
     /**/ 
     html, body { 
      height:100%; 
      text-align:center; 
     } 
     #wrap { 
      margin:auto; 
      min-height:100%; 
      margin-top:-100px; 
      text-align:left; 
     } 
     * html #wrap { 
      height:100% 
     } 
     #header { 
      background:red; 
      border-top:100px solid #fff; 
     } 
     #footer { 
      background:#eee; 
      margin:auto; 
      height:100px; 
      clear:both; 
     } 
     /**/ 
     #slideshow img{ 
      margin:0 0 0 55px; 
      height:100%; 
     } 

     div#thumbWrap { 
      position: relative; 
      height: 100px; 
      width: 500px; 
      overflow: auto; 
      margin:0 0 0 50px; 
     } 
     ul#thumbs { 
      display: block; 
      width: 2000px; 
      padding: 15px 0 0 15px; 
     } 
     ul#thumbs li { 
      display: block; 
      float: left; 
      padding: 0 4px; 
     } 
     ul#thumbs a { 
      display: block; 
      text-decoration: none; 
     } 
     ul#thumbs img { 
      border: 3px #fff solid; 
     } 
     ul#thumbs a:hover img { 
      opacity: 0.5; 
     } 
     </style> 

     </head> 

    <body> 
     <div id="wrap"> 
     <div id="header"> 

     </div><!-- #header --> 
     <div id="slideshow"> 
      <img src="images/01.jpg" alt="" /> 
      <img src="images/02.jpg" alt="" /> 
      <img src="images/03.jpg" alt="" /> 
      <img src="images/04.jpg" alt="" /> 
      <img src="images/05.jpg" alt="" /> 
      <img src="images/01.jpg" alt="" /> 
      <img src="images/02.jpg" alt="" /> 
      <img src="images/03.jpg" alt="" /> 
      <img src="images/04.jpg" alt="" /> 
      <img src="images/05.jpg" alt="" /> 
     </div><!-- #content --> 
     </div><!-- #wrap --> 

     <div id="footer"> 
      <div id="thumbWrap"> 
      <ul id="thumbs"> 

      </ul> 
      </div> 
     </div> 

     <script type="text/javascript"> 

     $(window).load(function() { 

      $("#slideshow img").load(function() { 
      alert('here'); 
      }) 

      resizeImg(); 
      /*-cycle 
      */ 
      $('#slideshow').cycle({ 
       fx:  'fade', 
       speed: 'fast', 
       timeout: 0, 
       pager: '#thumbs', 
       before: resizeImg(), 

       pagerAnchorBuilder: function(idx, slide) { 
        return '<li><a href="#"><img src="' + slide.src + '" width="auto" height="50" /></a></li>'; 
       } 
      }); 
      /*-thumbnailScroll 
      */ 
      var div = $('div#thumbWrap'), ul = $('ul#thumbs'), ulPadding = 15; 
      var divWidth = div.width(); 
      div.css('overflow','hidden'); 
      var lastLi = ul.find('li:last-child'); 
      div.mousemove(function(e){ 
      var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;   
      var left = (e.pageX - div.offset().left) * (ulWidth-divWidth)/divWidth;   
      div.scrollLeft(left);   
      }); 

      var footerHeight = $('#footer').height(); 

      function resizeImg() { 
      $('#slideshow img').css({'height':$('#wrap').height()-footerHeight,'width':'auto'}); 
      } 

      $(window) 
      .scroll(resizeImg) 
      .resize(resizeImg) 
      .onload(resizeImg) 
     }); 

     </script> 

    </body> 

    </html> 
+0

私は最近、別の質問のために書いた非常に簡単な機能http://stackoverflow.com/questions/10509694/jquery-how-to-check-if-images-have-finished-loading-in-ajax/10509808#10509808 –

答えて

2

これは過去にも私が取り組んできた不満な問題です。ブラウザによってイメージの読み込みが異なります。

私が使用した最も簡単な解決策は、jQuery.imagesLoaded pluginを使用することです。これもあなたのために働くかもしれません。