美化移动设备下界面的样式,并优化操作逻辑

This commit is contained in:
张梦南 2025-03-08 19:59:19 +08:00
parent a734192bfd
commit 4f607e63fb
8 changed files with 82 additions and 43 deletions

View File

@ -77,3 +77,11 @@ header .toggle-menu:hover {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); /* 添加阴影效果 */ box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); /* 添加阴影效果 */
} }
#logo_head {
font-family: 'Pacifico', cursive; /* 使用本地字体 Pacifico */
margin: 0;
padding-left: 10px;
text-align: left;
font-size: 32px;
color: rgb(117, 115, 115);
}

View File

@ -9,10 +9,12 @@
} }
#search-input { #search-input {
position: absolute;
width: 50%; /* 设置宽度为屏幕的50% */ width: 50%; /* 设置宽度为屏幕的50% */
padding: 5px 15px; padding: 5px 15px;
top: 10px; top: 72px;
left: 50%; /* 使搜索框居中 */ left: 50%; /* 使搜索框居中 */
z-index: 1000; /* 确保在顶部 */
} }
#search-input:hover, #search-input:hover,
@ -27,6 +29,7 @@
width: 80%; /* 设置侧边栏宽度为60% */ width: 80%; /* 设置侧边栏宽度为60% */
bottom: 0; bottom: 0;
transform: translateX(-100%); /* 默认隐藏侧边栏 */ transform: translateX(-100%); /* 默认隐藏侧边栏 */
z-index: 2000; /* 确保在顶部 */
} }
.sidebar.open { .sidebar.open {
@ -35,11 +38,15 @@
width: 80%; /* 确保侧边栏在打开时宽度为60% */ width: 80%; /* 确保侧边栏在打开时宽度为60% */
} }
.logo {
padding-top: 72px !important;
}
/* 小屏幕时主内容区 */ /* 小屏幕时主内容区 */
.main-content { .main-content {
margin-left: 0px; /* 小屏幕时移除左边距 */ margin-left: 0px; /* 小屏幕时移除左边距 */
margin-right: 0px; /* 小屏幕时右边距减小 */ margin-right: 0px; /* 小屏幕时右边距减小 */
margin-top: 60px; /* 小屏幕时稍微减小上边距 */ margin-top: 80px; /* 小屏幕时稍微减小上边距 */
} }
/* 小屏幕时头部 */ /* 小屏幕时头部 */
@ -47,6 +54,7 @@
height: 40px; /* 设置头部高度为50px */ height: 40px; /* 设置头部高度为50px */
justify-content: space-between; /* 保持头部内容在两端 */ justify-content: space-between; /* 保持头部内容在两端 */
align-items: center; /* 垂直居中内容 */ align-items: center; /* 垂直居中内容 */
z-index: 3000; /* 确保在顶部 */
} }
/* 小屏幕时菜单按钮 */ /* 小屏幕时菜单按钮 */
header .toggle-menu { header .toggle-menu {
@ -66,4 +74,8 @@
header .toggle-menu:hover { header .toggle-menu:hover {
background-color: rgba(235, 10, 10, 0.1); /* 增加轻微的背景色变化 */ background-color: rgba(235, 10, 10, 0.1); /* 增加轻微的背景色变化 */
} }
#logo_head {
width: 100%;
}
} }

View File

@ -7,6 +7,10 @@
top: 10px; top: 10px;
} }
#logo_head {
display: none;
}
#fullscreen-button { #fullscreen-button {
display: flex; /* 小屏幕隐藏头部全屏按钮 */ display: flex; /* 小屏幕隐藏头部全屏按钮 */
} }

View File

@ -15,8 +15,6 @@
z-index: 2000; z-index: 2000;
} }
.logo { .logo {
font-family: 'Pacifico', cursive; /* 使用本地字体 Pacifico */ font-family: 'Pacifico', cursive; /* 使用本地字体 Pacifico */
margin: 0; margin: 0;
@ -28,7 +26,7 @@
} }
.logo .part1 { .logo .part1 {
font-size: 50px; /* "ream" 字体较大 */ font-size: 50px; /* "dream" 字体较大 */
} }
.logo .part2 { .logo .part2 {
@ -93,3 +91,32 @@
align-items: center; /* 确保按钮水平居中 */ align-items: center; /* 确保按钮水平居中 */
padding-top: 30px; padding-top: 30px;
} }
/* 按钮样式:药丸形 */
.tag-btn {
display: block; /* 让按钮变成 block 级元素 */
width: 100px; /* 设置按钮的宽度 */
height: 34px; /* 设置按钮的高度 */
padding: 8px 10px; /* 调整内边距,让内容更舒适 */
border-radius: 20px;
color: #fff;
margin: 5px;
border: none;
cursor: pointer;
font-weight: bold; /* 加粗字体 */
text-align: center; /* 让文字居中 */
line-height: 17px; /* 调整文本垂直居中 */
transition: transform 0.5s ease, box-shadow 0.5s ease;
}
/* 按钮动画完成状态 */
.tag_btn.animated {
opacity: 1;
transform: translateY(0); /* 恢复到正常位置 */
}
/* 按钮悬停效果 */
.tag-btn:hover {
transform: scale(1.03);
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

View File

@ -104,31 +104,3 @@
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2); box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
} }
/* 按钮样式:药丸形 */
.tag-btn {
display: block; /* 让按钮变成 block 级元素 */
width: 100px; /* 设置按钮的宽度 */
height: 34px; /* 设置按钮的高度 */
padding: 8px 10px; /* 调整内边距,让内容更舒适 */
border-radius: 20px;
color: #fff;
margin: 5px;
border: none;
cursor: pointer;
font-weight: bold; /* 加粗字体 */
text-align: center; /* 让文字居中 */
line-height: 17px; /* 调整文本垂直居中 */
transition: transform 0.5s ease, box-shadow 0.5s ease;
}
/* 按钮动画完成状态 */
.tag_btn.animated {
opacity: 1;
transform: translateY(0); /* 恢复到正常位置 */
}
/* 按钮悬停效果 */
.tag-btn:hover {
transform: scale(1.03);
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
}

View File

@ -18,13 +18,15 @@
</head> </head>
<body> <body>
<header> <header>
<input type="text" id="search-input" placeholder="搜索工具...." /> <div class="logo_head" id="logo_head">DreamLife|ToolBox</div>
<button class="toggle-menu" id="toggle-menu"></button> <button class="toggle-menu" id="toggle-menu"></button>
<button id="fullscreen-button" class="fullscreen-btn"> <button id="fullscreen-button" class="fullscreen-btn">
<span class="icon">&#x26F6;</span> <span class="icon">&#x26F6;</span>
</button> </button>
</header> </header>
<input type="text" id="search-input" placeholder="搜索工具...." />
<aside id="sidebar" class="sidebar"> <aside id="sidebar" class="sidebar">
<div class="logo"> <div class="logo">
<span class="part1">DreamLife</span> <span class="part1">DreamLife</span>

View File

@ -4,12 +4,13 @@ const fullButton = document.getElementById('fullscreen-button');
// 监听滚动事件 // 监听滚动事件
window.addEventListener('scroll', function() { window.addEventListener('scroll', function() {
const scrollTop = window.scrollY || document.documentElement.scrollTop; // 获取滚动的距离 const scrollTop = window.scrollY || document.documentElement.scrollTop; // 获取滚动的距离
const isMobile = window.innerWidth <= 767; // 判断是否为移动设备
if (scrollTop > 50) { // 当页面滚动超过50px时 if (scrollTop > 50) { // 当页面滚动超过50px时
searchBox.style.top = '-50px'; // 将搜索框移出视口 searchBox.style.top = isMobile ? '14px' : '-50px'; // 将搜索框移出视口
fullscreenButton.style.top = '-50px'; // 让全屏按钮同步隐藏 fullscreenButton.style.top = '-50px'; // 让全屏按钮同步隐藏
} else { } else {
searchBox.style.top = '10px'; // 恢复到初始位置 searchBox.style.top = isMobile ? '72px' : '10px'; // 移动设备恢复到72px桌面端恢复到10px
fullscreenButton.style.top = '0px'; // 让全屏按钮同步恢复 fullscreenButton.style.top = '0px'; // 让全屏按钮同步恢复
} }
}); });

View File

@ -2,6 +2,9 @@
const menuButton = document.querySelector('.toggle-menu'); const menuButton = document.querySelector('.toggle-menu');
const sidebar = document.getElementById('sidebar'); const sidebar = document.getElementById('sidebar');
const menuButtons = document.querySelectorAll('.tag-btn');
// 侧边栏切换功能 // 侧边栏切换功能
menuButton.addEventListener('click', function(event) { menuButton.addEventListener('click', function(event) {
event.stopPropagation(); // 阻止事件冒泡,避免触发文档点击事件 event.stopPropagation(); // 阻止事件冒泡,避免触发文档点击事件
@ -9,13 +12,23 @@ menuButton.addEventListener('click', function(event) {
toggleRotation(); // 调用旋转按钮函数 toggleRotation(); // 调用旋转按钮函数
}); });
menuButtons.forEach(button => {
button.addEventListener('click', function(event) {
event.stopPropagation(); // 阻止事件冒泡
toggleSidebar(); // 关闭侧边栏
toggleRotation(); // 旋转按钮
});
});
// 侧边栏元素和按钮 // 侧边栏元素和按钮
function toggleSidebar() { function toggleSidebar() {
sidebar.classList.toggle('open'); // 切换侧边栏的显示/隐藏 if (window.innerWidth <= 768) { // 小屏幕显示菜单按钮
if (sidebar.classList.contains('open')) { sidebar.classList.toggle('open'); // 切换侧边栏的显示/隐藏
document.body.classList.add('no-scroll'); // 禁用滚动 if (sidebar.classList.contains('open')) {
} else { document.body.classList.add('no-scroll'); // 禁用滚动
document.body.classList.remove('no-scroll'); // 恢复滚动 } else {
document.body.classList.remove('no-scroll'); // 恢复滚动
}
} }
} }