jquery callback方法

jquery callback方法

callback函数在当前动画100%完成之后执行。

jquery动画的问题

许多jquery函数涉及动画。这些函数也许会将speed或duration作为可选参数。

例子: $(“p”).hide(“slow”)

speed或duration参数可以设置许多不同的值,比如”slow”,”fast”,”normal”或毫秒。

实例

以下实例在隐藏效果完全实现后回调函数。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.bootcss.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="https://cdn.bootcss.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>

猜你喜欢

转载自blog.csdn.net/weixin_41748874/article/details/80850446
今日推荐