参考:Slide Elements in Different Directions
▼button要素の次にある兄弟要素の左位置をアニメーションします
▼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>スタイル操作:高さと幅:outerWidth()の使用例 | jQuery</title> <link rel="stylesheet" type="text/css" href="/content/lib/global.css" /> <!-- JS --> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#slideleft button").click(function(){ var $lefty = $(this).next(); $left=parseInt($lefty.css('left'),10) == 0 ? -$lefty.outerWidth() : 0; $lefty.animate({ left: $left }); }); $('#slidemarginleft button').click(function() { var $marginlefty = $(this).next(); $margin=parseInt($marginlefty.css('marginLeft'),10) == 0 ? $marginlefty.outerWidth() : 0; $marginlefty.animate({ marginLeft: $margin }); }); }); </script> <!-- CSS --> <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; line-height:3em; padding:0 10px; background-color:orange; } </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>スタイル操作:高さと幅:outerWidth()の使用例 | 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 id="slideleft" class="slide"> <button>スライド!</button> <div>ボタンをクリックするとアニメーションします</div> </div> <br> <p>▼button要素の次にある兄弟要素の左外余白をアニメーションします</p> <div id="slidemarginleft" class="slide"> <button>スライド!</button> <div>ボタンをクリックするとアニメーションします</div> </div> <!-- / CODE --> </div> </body> </html>