jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。jQuery 动画是 jQuery 提供的一组方法,用于创建平滑的视觉效果。
fadeIn()
fadeOut()
slideUp()
slideDown()
animate()
complete
:动画完成后执行。start
:动画开始时执行。step
:动画每一步执行。<!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;
}
</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>
queue
参数控制动画队列。stop()
方法停止当前动画队列。jQuery 动画是一个强大且易于使用的工具,适用于各种需要动画效果的场景。通过合理使用 jQuery 动画方法,可以显著提升用户体验和页面交互性。
领取专属 10元无门槛券
手把手带您无忧上云