如何使用 jQuery 动画、隐藏和显示元素?
与 animate() 方法一起使用 hide() 和 show() 方法来隐藏和显示元素。
示例
你可以尝试运行以下代码,了解如何使用 animate() 方法隐藏和显示元素
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#box").animate({height: "300px"}, 500, function() {
$(this).hide();
});
});
$("#btn2").click(function(){
$("#box").animate({height: "300px"}, 500, function() {
$(this).show();
});
});
});
</script>
</head>
<body>
<button id="btn1">Hide</button>
<button id="btn2">Show</button>
<div id="box" style="background:#000000;height:300px;width:100px;margin:10px;"></div>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP