向上滑动隐藏元素
<!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').slideUp(3000)
}
</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').slideUp(3000)
}
function showFn() {
$('#showDiv').slideDown(2000)
}
</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()">
<input type="button" value="显示与隐藏div之间来回切换" onclick="toggleFn()">
<br><br>
<div id="showDiv">显示和隐藏</div>
<script>
function hideFn() {
$('#showDiv').slideUp(3000)
}
function showFn() {
$('#showDiv').slideDown(2000)
}
function toggleFn() {
$('#showDiv').slideToggle(2000)
}
</script>
</body>
</html>
点击右侧按钮: