本日  昨日
 
09/16(Mon) 18:21

o ページの自動スクローラ(2)
小ウィンドウを開き、開いたページを自動スクロールさせるスクリプトです。リンクも貼れるので、新着情報やメニューなどを表示するのに便利です。
下のスクリプトをHEAD部に記述します。
  1. html部分に小ウィンドウに表示する内容をhtml文を記述します。
  2. リンクを貼る場合は、
    <a href=\"JavaScript:window.opener.location.href='./xxx/xxxx.html';window.close();\">○○○</a>とlocationコマンドを使います。window.openerは小ウィンドウを開いた元ページにリンク先の内容を表示するコマンドです。
  3. yend = 80;はスクロールさせるページの縦方向の長さです。ページの最終行で反転するように値を調整します。
  4. ystp = 2;はスクロールの速度です。値を大きくすると早くなります。
  5. cond = true;はスクロール方法を指定します。trueは繰返スクロール、falseは反転スクロールです。
  6. window.open("","","width=320,height=100,scrollbars=1")のwidth=320,height=100で小ウィンドウのサイズを指定します。
<script language="JavaScript"> <!-- // ウインドウの自動スクローラ by「菊池さん」<http://kikuchisan.net/> // 自動スクロールする文章をここにHTML文で記述します html = "<html><head><title>自動スクローラ</title></head><body>\n"; html+= "<div style='font-size:10pt'>\n"; html+= "<center>★★ <font color=crimson>新着のご案内</font> ★★</center>\n"; html+= "■(03/02)ハッピーバースディのバグ修正機能追加<br>\n"; html+= "■(02/16)<a href=\"JavaScript:window.opener.location.href='"; html+= "../soft/cgi09.html';window.close();\">今日は何の日</a>に任意指定日機能追加<br>\n"; html+= "■(02/15)ソフト工作室にテロップ+画像反転(1)登録<br>\n"; html+= "■(02/13)ソフト工作室に<a href=\"JavaScript:window.opener.location.href='"; html+= "../java/java53.html';window.close();\">バイオリズム登録</a><br>\n"; html+= "■(02/01)万年カレンダー(2)をバージョンアップ<br>\n"; html+= "■(01/22)ソフト工作室のゲストブックのバグ修正<br>\n"; html+= "■(11/14)ソフト工作室に<a href=\"JavaScript:window.opener.location.href='"; html+= "../dhtml/dhtml11.html';window.close();\">画像トランジション表示</a><br>\n"; html+= "★月刊 「HOME PC」(2000年1月号)に当ページが紹介されました<br>\n"; html+= "</div></body></html>\n"; // 初期設定 var yaxs = 0; var yend = 80; //ページ縦長(pixel) var ystp = 2; //スクロール速度(pixel) var cond = true; //スクロール条件(true=繰返 false=反転) var timeID = 0 var scrollWindow = window.open("","","width=320,height=100,scrollbars=1"); scrollWindow.document.open(); scrollWindow.document.write(html); scrollWindow.document.close(); function scrWinpage() { if (scrollWindow.closed) return; clearTimeout(timeID); if (cond) { if (yaxs > yend) { yaxs = 0; } else { yaxs = yaxs + ystp; } //繰返 } else { yaxs = yaxs + ystp; if (yaxs < 0 || yaxs > yend) { ystp = -ystp; } //反転 } scrollWindow.scroll(0,yaxs); timeID = setTimeout("scrWinpage()",100); } // --> </script>
(注)IEで小ウィンドウを「×」マークで閉じるとエラーになる時は「OK」を押してください。


スクロールの実行
BODYタグに以下の内容を記述します。
<BODY onLoad="scrWinpage()" onUnload="clearTimeout(timeID)">

 
 
©1997- Kikuchisan's workshop All rights reserved //

スポンサーリンク

関連コンテンツ