PHP & JavaScript Room :: 設置サンプル

実行結果

設置サンプル

【参照】jQuery Image Preload Plugin

画像のプレロード(単一)

画像のプレロード(複数)

画像のプレロード(オブジェクトとして取得)


設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
      <title>設置サンプル</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript" src="/content/lib/jquery/jquery.imgpreload.js"></script>
      <script type="text/javascript">
         $(function(){
            /* demo1 */
            $.imgpreload('http://farm3.static.flickr.com/2526/4196070281_0a93789862_s.jpg',function()
            {
               // this = new image object
               // callback
               $("#demo1").append(this);
            });
            /* demo2 */
            $.imgpreload(['http://farm3.static.flickr.com/2526/4196070281_0a93789862_s.jpg','http://farm3.static.flickr.com/2689/4196824214_fdcf872e3d_s.jpg','http://farm3.static.flickr.com/2429/4196824188_28af5aaed7_s.jpg'],function()
            {
               // this = array of new image objects
               // callback executes when all images are loaded
               $("#demo2").append(this);
            });
            /* demo3, demo4 */
            $.imgpreload(['http://farm3.static.flickr.com/2526/4196070281_0a93789862_s.jpg','http://farm3.static.flickr.com/2689/4196824214_fdcf872e3d_s.jpg','http://farm3.static.flickr.com/2429/4196824188_28af5aaed7_s.jpg'],
            {
               each: function()
               {
                  // this = new image object
                  // callback executes on every image load
                  $("#demo3").append("<li><img src='"+this.src+"' /></li>");
               },
               all: function()
               {
                  // this = array of new image objects
                  // callback executes when all images are loaded
                  //$("#demo4").append(this);
                  for(var i=0; i<this.length; i++){
                     $("#demo4").append(this[i]);
                  }
               }
            });
         });
      </script>
      <!-- CSS -->
      <style type="text/css">
         ul { margin:0 0 10px 0; padding:0; overflow:hidden; }
         li { float:left; margin:0; padding:0; display:block; width:75px; height:75px; list-style:none; display:inline; }
      </style>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>設置サンプル</h1>
         <p>【参照】<a href='http://farinspace.com/2009/05/jquery-image-preload-plugin/'>jQuery Image Preload Plugin</a></p>
<!-- CODE -->
         <h2>画像のプレロード(単一)</h2>
         <div id="demo1"></div>
         <h2>画像のプレロード(複数)</h2>
         <div id="demo2"></div>
         <h2>画像のプレロード(オブジェクトとして取得)</h2>
         <ul id="demo3"></ul><br clear="all" />
         <div id="demo4"></div>
<!-- / CODE -->
      </div>
   </body>
</html>