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>


学び続ける
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!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>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  • おすすめコース
  • コースウェアのダウンロード
图片放大关闭