jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。图片转动是一种常见的动画效果,可以通过 jQuery 实现。
transform
属性实现图片转动。animate
方法实现图片转动。<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 图片转动</title>
<style>
.rotate {
animation: rotate 2s linear infinite;
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<img src="path/to/image.jpg" alt="Rotate Image" class="rotate">
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery 图片转动</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
#rotate-image {
transition: transform 2s linear;
}
</style>
</head>
<body>
<img id="rotate-image" src="path/to/image.jpg" alt="Rotate Image">
<button id="start-rotation">Start Rotation</button>
<script>
$(document).ready(function() {
$('#start-rotation').click(function() {
$('#rotate-image').css('transform', 'rotate(360deg)');
});
});
</script>
</body>
</html>
transform
属性或 animate
方法的参数,确保方向设置正确。transform
属性。通过以上方法,可以有效地实现和控制 jQuery 图片转动效果。
领取专属 10元无门槛券
手把手带您无忧上云