jQueryコールバックメソッド

jQuery アニメーションの問題

多くの jQuery 関数にはアニメーションが含まれます。これらの関数は、オプションの引数として速度または期間を取ることができます。

例: $("p").hide("slow")

速度または期間パラメータは、「遅い」、「速い」、「標準」、ミリ秒など、さまざまな値に設定できます。

インスタンス

次の例には、非表示効果が完全に実現された後のコールバック関数があります:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide("slow",function(){
      alert("段落现在被隐藏了");
    });
  });
});
</script>
</head>
<body>
<button>隐藏</button>
<p>点击“隐藏”按钮我就会消失</p>
</body>
</html>

次の例にはコールバック関数がなく、非表示効果が完了する前に警告ボックスがポップアップします:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide(1000);
    alert("现在段落被隐藏了");
  });
});
</script>
</head>
<body>
<button>隐藏</button>
<p>这是一个段落</p>
</body>
</html>


学び続ける
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <style type="text/css"> body{font-family: "微软雅黑";width: 420px; margin: 0 auto; text-align: center;} .box{ width: 200px; height: 200px; background: green; border: 1px solid #e6e6e6; margintop: 50px; line-height: 200px; position: absolute; } button{ border: none; background: green; width: 100px; height: 50px; line-height: 50px; color: #fff; font-size: 16px; margin-top: 50px; } </style> </head> <body> <button>点击开始动画</button> <div class="box" ></div> <script> $(document).ready(function(){ $("button").click(function(){ var div=$(".box"); div.animate({height:'200px',opacity:'0.4'},"slow"); div.animate({width:'200px',opacity:'0.8'},"slow"); div.animate({height:'100px',opacity:'0.4'},"slow"); div.animate({width:'100px',opacity:'0.8'},"slow"); div.animate({right:'100px',opacity:'0.8'},"slow"); div.animate({bottom:'100px',opacity:'0.8'},"slow"); div.animate({left:'100px',opacity:'0.8'},"slow"); div.animate({top:'100px',opacity:'0.8'},"slow",function(){ alert("The paragraph is over"); }); }); }); </script> <script> $(document).ready(function(){ $("button").click(function(){ var div=$(".box"); div.animate({height:'300px',opacity:'0.4'},"slow"); div.animate({width:'300px',opacity:'0.8'},"slow"); div.animate({height:'100px',opacity:'0.4'},"slow"); div.animate({width:'100px',opacity:'0.8'},"slow",function(){ alert("The paragraph is over");      }); }); }); }); </script> </body> </html>
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!