jqueryで上下左右でスライドして表示・非表示

  1. <!DOCTYPE html>
  2. <html lang="ja">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>jqueryで上下左右でスライドして表示・非表示</title>
  6. <script href="//www.google.com/jsapi" type="text/javascript"></script>
  7. <script type="text/javascript">
  8.   google.load("jquery", "1.4");
  9.   google.load("jqueryui", "1.7");
  10. </script>
  11. <script type="text/javascript">
  12.   (function($) {
  13.     $.extend({
  14.       slideEx: function(argElment, argDirection, argDelay) {
  15.         argElment.queue(function(){
  16.           if ($(this).css("display") == "none"){
  17.             $(this).show("slide", {direction: argDirection}, argDelay, function(){
  18.               $(this).clearQueue();
  19.             });
  20.           }
  21.           else {
  22.             $(this).hide("slide", {direction: argDirection}, argDelay, function(){
  23.               $(this).clearQueue();
  24.             });
  25.           }
  26.           $(this).dequeue();
  27.         });
  28.       }
  29.     });
  30.   })(jQuery);
  31.   
  32.   function test(argDirection) {
  33.     $.slideEx($("#wp"), argDirection, 1000);
  34.   }
  35. </script>
  36. </head>
  37. <body>
  38. <h1>jqueryで上下左右でスライドして表示・非表示</h1>
  39. <button onClick="test('right');">表示・非表示:右</button>
  40. <button onClick="test('left');">表示・非表示:左</button>
  41. <button onClick="test('up');">表示・非表示:上</button>
  42. <button onClick="test('down');">表示・非表示:下</button>
  43. <div id="wp" style="background:#ffeeee;border:1px solid #eedddd;padding:1em;margin-top:1em;">
  44. ここの部分が表示・非表示される<br />
  45. <br />
  46. お腹が空いた!<br />
  47. 丸ごとしまうまを食べることが出来るぐらいお腹が空いた!<br />
  48. </div>
  49. <div style="font-size:10pt;text-align:right;margin-top:0.5em;">
  50. <a href="//tips.recatnap.info/" target="_top">PCスキルの小技・忘却防止メモ</a> -
  51. <a href="//tips.recatnap.info/wiki/" target="_top">PCスキルの小技・忘却防止メモのまとめ(wiki)</a>
  52. </div>
  53. <div style="font-size:10pt;text-align:center;margin-top:0.5em;padding:0.5em;border-top:1px solid #ccc;">
  54. Copyright &copy; 2009 by PCスキルの小技・忘却防止メモ. All rights reserved.
  55. </div>
  56. </body>
  57. </html>