<!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;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1 {
color: #333;
margin-bottom: 30px;
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}
/* 主容器样式 */
.container {
width: 90%;
max-width: 800px;
margin: 0 auto;
}
/* 按钮样式 */
.btn {
display: inline-block;
padding: 12px 24px;
background-color: #4a90e2;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
margin: 10px;
transition: all 0.3s ease;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.btn:hover {
background-color: #357abd;
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
/* 面板样式 */
.panel {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.95);
z-index: 1000;
display: none;
overflow-y: auto;
padding: 20px;
box-sizing: border-box;
}
.panel-content {
max-width: 800px;
margin: 50px auto;
background-color: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
position: relative;
}
.close-btn {
position: absolute;
top: 15px;
right: 15px;
font-size: 24px;
color: #888;
cursor: pointer;
transition: all 0.3s ease;
}
.close-btn:hover {
color: #333;
transform: rotate(90deg);
}
.panel h2 {
color: #4a90e2;
margin-top: 0;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
}
.panel p {
line-height: 1.6;
color: #555;
}
/* 不同动画效果的样式 */
.fade-in {
opacity: 0;
}
.slide-in {
transform: translateY(-100%);
}
.zoom-in {
transform: scale(0.8);
opacity: 0;
}
.flip-in {
transform: perspective(1000px) rotateX(-90deg);
opacity: 0;
transform-origin: top center;
}
/* 参考文章样式 */
.reference {
margin-top: 50px;
padding: 15px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
max-width: 600px;
}
.reference a {
color: #1e88e5;
text-decoration: none;
word-break: break-all;
}
.reference a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div class="container">
<h1>jQuery过渡动画打开新面板特效</h1>
<button class="btn" id="fadeBtn">淡入淡出效果</button>
<button class="btn" id="slideBtn">滑动效果</button>
<button class="btn" id="zoomBtn">缩放效果</button>
<button class="btn" id="flipBtn">3D翻转效果</button>
<!-- 淡入淡出效果面板 -->
<div class="panel fade-in" id="fadePanel">
<div class="panel-content">
<span class="close-btn">×</span>
<h2>淡入淡出效果面板</h2>
<p>这是一个使用jQuery实现的淡入淡出过渡动画效果。面板会从完全透明逐渐变为不透明,关闭时则相反。</p>
<p>这种效果适合需要柔和过渡的场景,不会给用户带来突兀的感觉。</p>
<p>通过改变元素的opacity属性实现,配合transition或jQuery的animate方法。</p>
</div>
</div>
<!-- 滑动效果面板 -->
<div class="panel slide-in" id="slidePanel">
<div class="panel-content">
<span class="close-btn">×</span>
<h2>滑动效果面板</h2>
<p>这是一个使用jQuery实现的滑动过渡动画效果。面板会从上方滑入,关闭时则滑出。</p>
<p>滑动效果能很好地引导用户的视线,适合需要强调内容出现的场景。</p>
<p>通过改变元素的transform属性实现,使用translateY来控制垂直方向的位移。</p>
</div>
</div>
<!-- 缩放效果面板 -->
<div class="panel zoom-in" id="zoomPanel">
<div class="panel-content">
<span class="close-btn">×</span>
<h2>缩放效果面板</h2>
<p>这是一个使用jQuery实现的缩放过渡动画效果。面板会从小变大出现,关闭时则从大变小消失。</p>
<p>缩放效果能吸引用户注意力,适合需要突出显示重要内容的场景。</p>
<p>通过改变元素的transform属性实现,使用scale来控制大小变化。</p>
</div>
</div>
<!-- 3D翻转效果面板 -->
<div class="panel flip-in" id="flipPanel">
<div class="panel-content">
<span class="close-btn">×</span>
<h2>3D翻转效果面板</h2>
<p>这是一个使用jQuery实现的3D翻转过渡动画效果。面板会像卡片一样翻转出现,关闭时则翻转消失。</p>
<p>3D效果能增加界面的立体感和现代感,适合需要展示高级效果的场景。</p>
<p>通过改变元素的transform属性实现,使用perspective和rotateX来创建3D效果。</p>
</div>
</div>
</div>
<!-- 引入jQuery库 -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// 淡入淡出效果
$("#fadeBtn").click(function() {
$("#fadePanel").fadeIn(400);
});
// 滑动效果
$("#slideBtn").click(function() {
$("#slidePanel").css("display", "block").animate({
"transform": "translateY(0)"
}, 400);
});
// 缩放效果
$("#zoomBtn").click(function() {
$("#zoomPanel").css({
"display": "block",
"opacity": 0,
"transform": "scale(0.8)"
}).animate({
"opacity": 1,
"transform": "scale(1)"
}, 400);
});
// 3D翻转效果
$("#flipBtn").click(function() {
$("#flipPanel").css({
"display": "block",
"opacity": 0,
"transform": "perspective(1000px) rotateX(-90deg)"
}).animate({
"opacity": 1,
"transform": "perspective(1000px) rotateX(0deg)"
}, 500);
});
// 关闭按钮事件
$(".close-btn").click(function() {
var panel = $(this).closest(".panel");
if (panel.hasClass("fade-in")) {
panel.fadeOut(300);
}
else if (panel.hasClass("slide-in")) {
panel.animate({
"transform": "translateY(-100%)"
}, 300, function() {
panel.css("display", "none");
});
}
else if (panel.hasClass("zoom-in")) {
panel.animate({
"opacity": 0,
"transform": "scale(0.8)"
}, 300, function() {
panel.css("display", "none");
});
}
else if (panel.hasClass("flip-in")) {
panel.animate({
"opacity": 0,
"transform": "perspective(1000px) rotateX(-90deg)"
}, 400, function() {
panel.css("display", "none");
});
}
});
// 点击面板外部关闭
$(".panel").click(function(e) {
if ($(e.target).hasClass("panel")) {
$(this).fadeOut(300);
}
});
});
</script>
</body>
</html>
1764

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



