参照:How to build a Google like Ajax loader: the red loading... bar
外部ファイルを読込んでいる間、ページの左上に「Loading content...」というローディング表示をし、読込完了時にそれを非表示にします。
<!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>イベント操作:イベントハンドリング:bindの使用例 | jQuery</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ /* ajaxをコールする度にローディング表示 */ $("#loading").bind("ajaxSend", function(){ $(this).show(); }).bind("ajaxComplete", function(){ $(this).hide(); }); }); function ajaxLoad(){ /* ajaxで外部ファイルを読込みます */ $("#loadedContent").html("").load('/content/demo/loading.php'); } </script> <!-- CSS --> <style type="text/css"> /* ajax loader */ #loading{ position:fixed; top:0; left:0; z-index:5000; padding:2px; background-color:red; color:#fff; font-size:150%; display:none; } </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 & JavaScript Room</a> :: 設置サンプル</h1> <h3 class='h'>実行結果</h3> <div id="wrap"> <h1>イベント操作:イベントハンドリング:bindの使用例 | jQuery</h1> <h2>Google風のAjaxローダー</h2> <p>参照:<a href='http://blog.4webby.com/posts/view/7/how_to_build_a_google_like_ajax_loader_the_red_loading_bar'>How to build a Google like Ajax loader: the red loading... bar</a></p> <p>外部ファイルを読込んでいる間、ページの左上に「Loading content...」というローディング表示をし、読込完了時にそれを非表示にします。</p> <!-- CODE --> <p><input type="button" onclick="ajaxLoad()" value="外部ファイル読込処理実行" /></p> <div id="loadedContent"></div> <div id="loading">Loading content...</div> <!-- / CODE --> </div> </body> </html>