理解:多次触发动画会造成动画积压,先使用stop清除前面所有动画,然后在触发一个动画。这样就不会有问题了。
动画排队:
<!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>
<script src="./jquery-3.6.0.js"></script>
<style>
button{
width: 100px;
height: 50px;
}
div{
display: none;
width: 300px;
height: 500px;
background-color: aqua;
}
</style>
</head>
<body>
<script>
$(function(){
$("button").hover(function(){
$("div").slideToggle("1000")
})
})
</script>
<button></button>
<div></div>
</body>
</html>
解决-动画排队
代码:
<!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>
<script src="./jquery-3.6.0.js"></script>
<style>
button{
width: 100px;
height: 50px;
}
div{
display: none;
width: 300px;
height: 500px;
background-color: aqua;
}
</style>
</head>
<body>
<script>
$(function(){
$("button").hover(function(){
$("div").stop().slideToggle("1000")
})
})
</script>
<button></button>
<div></div>
</body>
</html>