jQuery 是一个快速、小巧且功能丰富的 JavaScript 库,它简化了 HTML 文档遍历、事件处理、动画和 Ajax 交互。鼠标悬停效果通常用于在用户将鼠标指针移动到某个元素上时,改变该元素的视觉表现。
以下是一个简单的 jQuery 鼠标悬停效果的示例:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Hover Effect</title>
<style>
.hover-effect {
width: 200px;
height: 100px;
background-color: #3498db;
color: white;
text-align: center;
line-height: 100px;
margin: 20px;
}
.hover-effect:hover {
background-color: #e74c3c;
}
</style>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="hover-effect">Hover Me!</div>
<script>
$(document).ready(function() {
$('.hover-effect').hover(
function() {
// 鼠标进入时的效果
$(this).css('background-color', '#2ecc71');
},
function() {
// 鼠标离开时的效果
$(this).css('background-color', '#3498db');
}
);
});
</script>
</body>
</html>
通过以上方法,可以有效地实现和调试 jQuery 鼠标悬停效果。
云+社区沙龙online第5期[架构演进]
云+社区沙龙online [新技术实践]
云+社区沙龙online [新技术实践]
TVP技术夜未眠
企业创新在线学堂
算法大赛
2022vivo开发者大会
领取专属 10元无门槛券
手把手带您无忧上云