jQuery 回呼方法

jQuery 動畫的問題

許多 jQuery 函數涉及動畫。這些函數也許會將 speed 或 duration 作為可選參數。

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

speed 或 duration 參數可以設定許多不同的值,例如"slow", "fast", "normal"或毫秒。

實例

以下實例在隱藏效果完全實現後回呼函數:

<!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學習者快速成長!