jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。点击旋转按钮使图片消失的功能可以通过 jQuery 的事件绑定和 CSS 动画来实现。
.click()
方法绑定点击事件。原因:
解决方法:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Rotate and Hide Image</title>
<style>
#myImage.rotate {
animation: rotate 1s linear forwards;
}
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<img id="myImage" src="path/to/your/image.jpg" alt="My Image">
<button id="rotateButton">Rotate and Hide</button>
<script>
$(document).ready(function() {
$('#rotateButton').click(function() {
$('#myImage').addClass('rotate');
setTimeout(function() {
$('#myImage').hide();
}, 1000); // 1秒后隐藏图片
});
});
</script>
</body>
</html>
通过以上代码,你可以实现点击旋转按钮后图片旋转并消失的效果。确保所有元素 ID 和路径正确,并且 jQuery 库已正确加载。
没有搜到相关的文章