隐藏动画
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/jquery-3.7.1.js"></script>
<style>
#showDiv {
width: 300px;
height: 300px;
background-color: pink;
}
</style>
</head>
<body>
<input type="button" value="点击按钮隐藏div" onclick="hideFn()"><br><br>
<div id="showDiv">显示和隐藏</div>
<script>
function hideFn() {
$('#showDiv').hide('slow', function () {
alert('动画结束了')
})
}
</script>
</body>
</html>
点击上面按钮:
# 显示动画
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/jquery-3.7.1.js"></script>
<style>
#showDiv {
width: 300px;
height: 300px;
background-color: pink;
}
</style>
</head>
<body>
<input type="button" value="点击按钮隐藏div" onclick="hideFn()">
<input type="button" value="点击按钮显示div" onclick="showFn()"><br><br>
<div id="showDiv">显示和隐藏</div>
<script>
function hideFn() {
$('#showDiv').hide(3000, 'linear')
}
function showFn() {
$('#showDiv').show(3000, 'linear')
}
</script>
</body>
</html>
先点击最左侧按钮隐藏div:
然后点击右侧按钮显示div:
切换显示和隐藏
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="js/jquery-3.7.1.js"></script>
<style>
#showDiv {
width: 300px;
height: 300px;
background-color: pink;
}
</style>
</head>
<body>
<input type="button" value="点击按钮隐藏div" onclick="hideFn()">
<input type="button" value="点击按钮显示div" onclick="showFn()">
<input type="button" value="点击按钮切换div显示和隐藏" onclick="toggleFn()">
<br><br>
<div id="showDiv">显示和隐藏</div>
<script>
function hideFn() {
$('#showDiv').hide(3000, 'linear')
}
function showFn() {
$('#showDiv').show(3000, 'linear')
}
function toggleFn() {
$('#showDiv').toggle(2000)
}
</script>
</body>
</html>
点击最右侧按钮:
再点击最右侧按钮: