jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。jQuery 的动画功能允许开发者通过简单的 API 调用来创建复杂的动画效果。
fadeIn()
fadeOut()
slideUp()
slideDown()
animate()
stop()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jQuery 动画示例</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#box {
width: 100px;
height: 100px;
background-color: red;
margin: 20px;
}
</style>
</head>
<body>
<div id="box"></div>
<button id="animateBtn">开始动画</button>
<script>
$(document).ready(function() {
$('#animateBtn').click(function() {
$('#box').animate({
width: '200px',
height: '200px',
opacity: 0.5
}, 1000, function() {
console.log('动画完成');
});
});
});
</script>
</body>
</html>
stop()
方法停止当前动画,再开始新的动画。通过以上内容,你应该对 jQuery 动画有了全面的了解,包括其基础概念、优势、类型、应用场景以及常见问题的解决方法。
领取专属 10元无门槛券
手把手带您无忧上云