show 和 hide
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>hide和show</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('mouseenter', function () {
$(this).next().show(1000, 'swing')
})
$('.demo').on('mouseleave', function () {
$('p').next().hide(3000, 'linear')
})
</script>
</html>
fadeIn 和 fadeOut
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>動畫</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('click', function () {
if ($(this).next().css('display') == 'none') {
$(this).next().fadeIn()
} else {
$(this).next().fadeOut()
}
})
</script>
</html>
fadeToggle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>動畫</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('click', function () {
$(this).next().fadeToggle(3000)
})
</script>
</html>
fadeTo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>動畫</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('click', function () {
if ($(this).next().css('display') == 'none') {
$(this).next().fadeTo(1500, 0.7, 'swing', function () {
console.log("fadeTo1")
})
} else {
$(this).next().fadeTo(1500, 0.1, 'swing', function () {
console.log("fadeTo2")
})
}
})
</script>
</html>
slideDown 和 slideUp
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>動畫</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('click', function () {
if ($(this).next().css('display') == 'none') {
$(this).next().slideDown(1500, 'swing', function () {
console.log("slideDown")
})
} else {
$(this).next().slideUp(1500, 'swing', function () {
console.log("slideUp")
})
}
})
</script>
</html>
slideToggle
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>溫故而知"心"</title>
<style>
p {
width: 100px;
border: 1px solid #ff0000;
}
ul {
list-style: none;
display: none;
}
</style>
</head>
<body>
<div class="demo">
<p>動畫</p>
<ul>
<li>11111111111</li>
<li>22222222222</li>
<li>33333333333</li>
</ul>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<script>
$('p').on('click', function () {
$(this).next().slideToggle(1500)
})
</script>
</html>