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

実行結果

DOM選択処理:調査:next()の使用例 | jQuery

参考:Slide Elements in Different Directions

▼button要素の次にある兄弟要素をスライドアップ・ダウンします

ボタンをクリックするとスライドアップ・ダウンします

設置サンプルのソース

<!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>DOM選択処理:調査:next()の使用例 | jQuery</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
      <script type="text/javascript">
         $(function(){
            $("button").click(function(){
               $(this).next().slideToggle();
            });
         });
      </script>
      <style type="text/css">
         .slide{
            position:relative;
            width:350px; height:100px;
            background-color:#ffffcc;
            border:1px solid #999;
            overflow:hidden;
         }
         .slide button {
            margin:0.7em 0 0 0.7em;
         }
         .slide div {
            position:absolute;
            left:0; bottom:0;
            width:100%; height:3em;
            padding:0 10px;
            background-color:orange;
            color:#333333;
            line-height:3em;
         }
      </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>DOM選択処理:調査:next()の使用例 | jQuery</h1>
         <p>参考:<a href='http://www.learningjquery.com/2009/02/slide-elements-in-different-directions'>Slide Elements in Different Directions</a></p>
<!-- CODE -->
         <p>▼button要素の次にある兄弟要素をスライドアップ・ダウンします</p>
         <div class="slide">
            <button>スライド!</button>
            <div>ボタンをクリックするとスライドアップ・ダウンします</div>
         </div>
<!-- / CODE -->
      </div>
   </body>
</html>