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

実行結果

Create a Simple CSS + Javascript Tooltip with jQuery | 設置サンプル

▼リンクにマウスオーバーするとツールチップが表示されます。

「PHP & JavaScript Room」は、 PHPJavaScriptスタイルシート、 Webページ埋め込みによる音声・動画のストリーム配信方法など、サイト作成に役立つ実用的なプログラミング・テクニックを解説しています。

設置サンプルのソース

<!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>Create a Simple CSS + Javascript Tooltip with 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() {
            //Select all anchor tag with rel set to tooltip
            $('a[rel=tooltip]').mouseover(function(e) {
               
               //Grab the title attribute's value and assign it to a variable
               var tip = $(this).attr('title');   
               
               //Remove the title attribute's to avoid the native tooltip from the browser
               $(this).attr('title','');
               
               //Append the tooltip template and its value
               $(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');      
                     
               //Show the tooltip with faceIn effect
               $('#tooltip').fadeIn('500');
               $('#tooltip').fadeTo('10',0.9);
               
            }).mousemove(function(e) {
               //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
               $('#tooltip').css('top', e.pageY + 10 );
               $('#tooltip').css('left', e.pageX + 20 );
               
            }).mouseout(function() {
               //Put back the title attribute's value
               $(this).attr('title',$('.tipBody').html());
               //Remove the appended tooltip template
               $(this).children('div#tooltip').remove();
               
            });
         });
      </script>
      <!-- CSS -->
      <style type="text/css">
         div.para { width:500px; }
         div.para a { font-weight:bold; text-decoration:underline; cursor:pointer; }
         /* Tooltip */
         #tooltip { position:absolute; z-index:9999; color:#fff; font-size:10px; width:180px; }
         #tooltip .tipHeader { height:8px; background:url(/content/img/ajax/tipHeader.gif) no-repeat; }
         #tooltip .tipBody { background-color:#000; padding:5px 5px 5px 15px; }
         #tooltip .tipFooter { height:8px; background:url(/content/img/ajax/tipFooter.gif) no-repeat; }
      </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><a href='http://www.queness.com/post/92/create-a-simple-cssjavascript-tooltip-with-jquery'>Create a Simple CSS + Javascript Tooltip with jQuery</a> | 設置サンプル</h1>
         <p>▼リンクにマウスオーバーするとツールチップが表示されます。</p>
<!-- CODE -->
         <div class="para">
            <a rel="tooltip" title="<img src='/content/img/mythumb.png' width='150' height='150' />">「PHP & JavaScript Room」</a>は、
            <a rel="tooltip" title="<strong>Hypertext Preprocessor</strong><br>Webページ作成のために用いられるプログラミング言語の一種。">PHP</a>、
            <a rel="tooltip" title="<strong>JavaScript</strong>(略称:JS)<br>主にWebブラウザ上で動作し、HTMLの動的書き換えや入力フォームの自動補完など、ウェブページの使用感向上を目的として使用されたり、リッチクライアントアプリケーションの構築に使われる。">JavaScript</a>、
            <a rel="tooltip" title="<strong>Style Sheet</strong>ドキュメント文書において表示形式を制御する概念。">スタイルシート</a>、
            Webページ埋め込みによる音声・動画のストリーム配信方法など、サイト作成に役立つ実用的なプログラミング・テクニックを解説しています。
         </div>
<!-- / CODE -->
      </div>
   </body>
</html>