jQuery的基本动画函数
show() 显示
语法:元素.show( 运动时间 ,运动曲线 ,运动结束的回调函数)
hide() 隐藏
语法:元素.hide( 运动时间 ,运动曲线 ,运动结束的回调函数)
toggle() 切换
本身如果是隐藏的,就显示
本身如果是显示的,就隐藏
语法:元素.toggle( 运动时间 ,运动曲线 ,运动结束的回调函数)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
div{
width: 300px;
height: 300px;
background-color: skyblue;
}
</style>
</head>
<body>
<button>show</button>
<button>hide</button>
<button>toggle</button>
<div></div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
$('button:nth-child(1)').click(function(){
$('div').show(1000,'linear',function(){console.log('show结束了')})
})
$('button:nth-child(2)').click(function(){
$('div').hide(1000,'linear',function(){console.log('hide结束了')})
})
$('button:nth-child(3)').click(function(){
$('div').toggle(1000,'linear',function(){console.log('toggle结束了')})
})
</script>
</body>
</html>