<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>炫酷图片放大切换效果</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #001510);
color: white;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 20px;
}
.header {
text-align: center;
margin-bottom: 40px;
max-width: 800px;
}
h1 {
font-size: 3.5rem;
margin-bottom: 15px;
text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
background: linear-gradient(45deg, #ff8a00, #e52e71, #22c1c3);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
animation: hueRotate 8s infinite linear;
}
.subtitle {
font-size: 1.4rem;
opacity: 0.85;
margin-bottom: 25px;
}
.gallery {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 30px;
max-width: 1200px;
width: 100%;
}
.image-card {
position: relative;
height: 280px;
border-radius: 15px;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
cursor: pointer;
transition: transform 0.3s ease;
}
.image-card:hover {
transform: translateY(-10px);
}
.image-card img {
width: 100%;
height: 100%;
object-fit: cover;
transition: all 0.5s ease;
}
.image-card:hover img {
transform: scale(1.2);
filter: brightness(1.1);
}
.overlay {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
padding: 20px;
background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
transform: translateY(40px);
transition: transform 0.4s ease;
opacity: 0;
}
.image-card:hover .overlay {
transform: translateY(0);
opacity: 1;
}
.title {
font-size: 1.6rem;
font-weight: 600;
margin-bottom: 8px;
}
.description {
font-size: 0.95rem;
opacity: 0.8;
}
.special-link {
display: block;
margin: 50px auto;
text-align: center;
padding: 15px 40px;
background: linear-gradient(45deg, #ff416c, #ff4b2b);
color: white;
font-size: 1.3rem;
text-decoration: none;
border-radius: 50px;
box-shadow: 0 5px 15px rgba(255, 75, 43, 0.4);
transition: all 0.3s ease;
width: fit-content;
}
.special-link:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(255, 75, 43, 0.6);
background: linear-gradient(45deg, #ff4b2b, #ff416c);
}
.footer {
margin-top: 50px;
text-align: center;
font-size: 1rem;
opacity: 0.7;
max-width: 800px;
}
@keyframes hueRotate {
0% { filter: hue-rotate(0deg); }
100% { filter: hue-rotate(360deg); }
}
@media (max-width: 768px) {
h1 {
font-size: 2.5rem;
}
.subtitle {
font-size: 1.1rem;
}
.gallery {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="gallery">
<div class="image-card">
<img src="https://images.unsplash.com/photo-1501854140801-50d01698950b?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80" alt="山脉风景">
<div class="overlay">
<div class="title">壮丽山脉</div>
<div class="description">高耸入云的雪山,纯净的自然风光</div>
</div>
</div>
<div class="image-card">
<img src="https://images.unsplash.com/photo-1475924156734-496f6cac6ec1?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80" alt="海滩日落">
<div class="overlay">
<div class="title">海滩日落</div>
<div class="description">金色阳光洒在波光粼粼的海面上</div>
</div>
</div>
<div class="image-card">
<img src="https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80" alt="森林景观">
<div class="overlay">
<div class="title">神秘森林</div>
<div class="description">阳光穿过茂密树叶的神秘森林小径</div>
</div>
</div>
<div class="image-card">
<img src="https://images.unsplash.com/photo-1511497584788-876760111969?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1200&q=80" alt="城市夜景">
<div class="overlay">
<div class="title">城市夜景</div>
<div class="description">现代都市的璀璨灯火与迷人夜景</div>
</div>
</div>
</div>
<div class="footer">
<p>使用jQuery实现的炫酷图片放大切换效果 | 悬停查看动画效果 | 响应式设计</p>
</div>
<script>
$(document).ready(function() {
// 添加悬停效果
$('.image-card').hover(
function() {
// 鼠标进入
$(this).find('img').css({
'transform': 'scale(1.2)',
'filter': 'brightness(1.1)'
});
$(this).find('.overlay').css({
'transform': 'translateY(0)',
'opacity': '1'
});
},
function() {
// 鼠标离开
$(this).find('img').css({
'transform': 'scale(1)',
'filter': 'brightness(1)'
});
$(this).find('.overlay').css({
'transform': 'translateY(40px)',
'opacity': '0'
});
}
);
// 添加点击效果
$('.image-card').click(function() {
// 创建全屏覆盖层
const overlay = $('<div class="fullscreen-overlay"></div>');
const imgSrc = $(this).find('img').attr('src');
// 添加样式
overlay.css({
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0,0,0,0.9)',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
zIndex: 1000,
cursor: 'pointer'
});
// 添加图片
const fullImg = $('<img>').attr('src', imgSrc).css({
maxWidth: '90%',
maxHeight: '90%',
borderRadius: '10px',
boxShadow: '0 0 40px rgba(255,255,255,0.2)'
});
overlay.append(fullImg);
$('body').append(overlay);
// 点击关闭
overlay.click(function() {
$(this).fadeOut(400, function() {
$(this).remove();
});
});
});
});
</script>
</body>
</html>
1139

被折叠的 条评论
为什么被折叠?



