<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery悬停边框动画特效</title>
<style>
body {
font-family: 'Arial', sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f5f5f5;
margin: 0;
padding: 20px;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 30px;
max-width: 1200px;
}
.box {
width: 200px;
height: 200px;
background-color: white;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
position: relative;
overflow: hidden;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
.box::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 3px solid transparent;
border-radius: 10px;
box-sizing: border-box;
transition: all 0.5s ease;
}
.box:hover {
transform: translateY(-5px);
box-shadow: 0 15px 30px rgba(0,0,0,0.2);
}
.box:hover::before {
border-color: #3498db;
animation: borderAnimation 2s infinite linear;
}
.box-content {
text-align: center;
padding: 20px;
z-index: 1;
}
@keyframes borderAnimation {
0% {
border-top-color: #3498db;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: transparent;
}
25% {
border-top-color: #3498db;
border-right-color: #3498db;
border-bottom-color: transparent;
border-left-color: transparent;
}
50% {
border-top-color: #3498db;
border-right-color: #3498db;
border-bottom-color: #3498db;
border-left-color: transparent;
}
75% {
border-top-color: #3498db;
border-right-color: #3498db;
border-bottom-color: #3498db;
border-left-color: #3498db;
}
100% {
border-top-color: transparent;
border-right-color: #3498db;
border-bottom-color: #3498db;
border-left-color: #3498db;
}
}
.special-link {
position: fixed;
bottom: 20px;
right: 20px;
color: #3498db;
text-decoration: none;
font-size: 12px;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
<div class="box-content">
<h3>悬停效果1</h3>
<p>鼠标悬停查看边框动画</p>
</div>
</div>
<div class="box">
<div class="box-content">
<h3>悬停效果2</h3>
<p>鼠标悬停查看边框动画</p>
</div>
</div>
<div class="box">
<div class="box-content">
<h3>悬停效果3</h3>
<p>鼠标悬停查看边框动画</p>
</div>
</div>
<div class="box">
<div class="box-content">
<h3>悬停效果4</h3>
<p>鼠标悬停查看边框动画</p>
</div>
</div>
</div>
<a href="https://a.88a.org.cn/OrP8" class="special-link">更多特效</a>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// 增强悬停效果
$('.box').hover(
function() {
// 鼠标进入
$(this).css('transform', 'translateY(-10px)');
},
function() {
// 鼠标离开
$(this).css('transform', 'translateY(0)');
}
);
// 点击效果
$('.box').click(function() {
$(this).toggleClass('active');
if ($(this).hasClass('active')) {
$(this).find('h3').css('color', '#e74c3c');
} else {
$(this).find('h3').css('color', '#333');
}
});
});
</script>
</body>
</html>