JavaScript Market - 動きのあるホームページを作る為の各種JavaScript のサンプルと小技集を公開中

JavaScript

JavaScriptって…? | JavaScript応用のツボ | ブラウザについて | JavaScript Market 利用規程 | JavaScript 各種サンプル | JavaScript 小技集

窓を開いてリンクの案内を表示

■ 2002,03,26 IE for Macに対して処理を無効にするルーチンを追加

マウスポインタがリンクに乗ると、
アニメーションっぽい感じで窓を開いて案内文を表示します。
ページのドコに使っても必ずマウスの右側に現れます。
設置するときに座標を考える必要がありませんが、
このままの状態だと、ページの右端などに作ったリンクでは窓が隠れる事があります。
その場合は、窓の出現位置調整部で調整して下さい。
尚、IE for Macでは意図した処理が行われない為、一切の処理が行われないようになっています。

リンク1 
リンク2 
リンク3
■ このスクリプトのソース
<style type=text/css>
/* 案内窓の基本設定 */
.infwin  { position:absolute; border:1px solid; visibility:hidden; overflow:hidden; }
/* 案内内の表示設定 */
.inftd   { font-size:10pt; text-align:center; }
</style>

<script>
infval = new Array();

/* 必要な案内文数分のデータをカンマで区切って記述
   形式 = ",レイヤ名,案内文(タグ可),窓の横サイズ,窓の縦サイズ,文字色,背景色,枠色" */
infval[1] = "lay,リンク1の説明文です,150,80,#000000,#ffffff,#0000ff";
infval[2] = "lay,リンク2の説明文です,150,80,#000000,#ffffff,#0000ff";
infval[3] = "lay,リンク3の説明文です,150,80,#000000,#ffffff,#0000ff";

/* 窓を開く速度 */
speed = 10;

/* 窓の出現位置調整 */
off_left = 40; // 横方向
off_top = 50;  // 縦方向

var id;
function open_set(n) {

   if (navigator.userAgent.match(/msie/i) && navigator.userAgent.match(/mac/i))
      return;

   if (n) {
      inf = infval[n].split(",");
      pos = inf[0]; mes = inf[1]; rw = inf[2]; rh = inf[3];
      tx = inf[4]; bg = inf[5]; bd = inf[6];
   }

   clearTimeout(id);
   if (rw >= rh) {
      sw = rw / speed;
      sh = sw / (rw / rh);
   }
   if (rh >= rw) {
      sh = rh / speed;
      sw = sh / (rh / rw);
   }
   mw = rw; mh = rh; ml = rx; mt = ry;
   rl = rx + (rw / 2); rt = ry + (rh / 2);
   if (document.layers) doc = document.layers[pos];
   else if (document.all) doc = document.all.item(pos);
   else if (document.getElementById) doc = document.getElementById(pos);

   if (n) {
      if (document.layers) {
         with (doc) { left = rl; top = rt; bgColor = bg; visibility = "visible"; }
         mes = "<table border=0 bgcolor=" + bd + " cellpadding=1 cellspacing=0 width="
          + mw + " height=" + mh + "><td><table border=0 bgcolor="
          + bg + " cellspacing=0 width=100% height=" + (mh-2)
          + "><td class=inftd><font color=" + tx + ">" + mes
          + "</font></td></table></td></table>";
      }
      else {
         with (doc.style) {
            left = rx; top = ry;
            borderColor = bd; background = bg;
            visibility = "visible";
         }
         mes = "<table width=" + mw + " height=" + mh + "><td class=inftd>"
             + "<font color=" + tx + ">" + mes + "</font></td></table>";
      }
      w = h = 0;
      lay_open();
   }
   else {
      if (document.layers)
         with (doc) {
            with (document) { open(); write(""); close(); }
            resizeTo(0,0); visibility = "hidden";
         }
      else {
         doc.innerHTML = "";
         with (doc.style) { width = 0; height = 0; visibility = "hidden"; }
      }
   }
}

function lay_open() {

   w += sw;
   h += sh;
   rl -= sw / 2;
   rt -= sh / 2;
   if (w > mw) w = mw; if (h > mh) h = mh;
   if (rl < ml) rl = ml; if (rt < mt) rt = mt;
   if (document.layers) with (doc) {
      left = rl; top = rt; resizeTo(w,h);
      document.open();
      document.write("<table border=0 bgcolor=" + bd
       + " cellpadding=1 cellspacing=0 width="+w+" height=" + h
       + "><td><table border=0 bgcolor=" + bg
       + " cellspacing=0 width=100% height=" + (h-2)
       + "><td><br></td></table></td></table>");
      document.close();
   }
   else with (doc.style) { left = rl; top = rt; width = w; height = h; }
   if (w < mw || h < mh) id = setTimeout("lay_open()",0);
   else if (document.layers) with (doc.document) { open(); write(mes); close(); }
   else doc.innerHTML = mes;
}

function mouse_pos(e) {

   if (document.layers) {
      rx = e.pageX;
      ry = e.pageY;
   }
   else if (document.all) {
      rx = event.clientX + document.body.scrollLeft;
      ry = event.clientY + document.body.scrollTop;
   }
   else if (document.getElementsByName) {
      rx = e.pageX;
      ry = e.pageY;
   }
   rx += off_left; ry -= off_top;
}

if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = mouse_pos;

// Copyright (C) 2002-2002 suepon , All rights reserved.
// Script found at http://suepon.com/
</script>

<span id=lay class=infwin><layer name=lay></layer></span>

<!-- onMouseover="open_set(案内文番号)" onMouseout="open_set()" -->
<a href="" onMouseover="open_set(1)" onMouseout="open_set()">リンク1</a>
<a href="" onMouseover="open_set(2)" onMouseout="open_set()">リンク2</a>
<a href="" onMouseover="open_set(3)" onMouseout="open_set()">リンク3</a>


suepon.com | CGI作成・CGI制作 | ドメイン検索 | バナー自動作成 | Google Dance jp | 松浦亜弥 (H.P.memo) | パソコン | ネイル