|
21 | 21 | margin: 0; |
22 | 22 | padding: 0; |
23 | 23 | height: 100%; |
24 | | - background-color: #000000; /* 基础背景色为黑色 */ |
| 24 | + background-color: #000000; /* 默认竖屏模式为黑色背景 */ |
25 | 25 | overflow-x: hidden; /* 防止水平滚动 */ |
26 | 26 | } |
27 | 27 |
|
| 28 | + /* 横屏模式下隐藏黑色背景,使用透明背景 */ |
| 29 | + @media (min-width: 584px) { |
| 30 | + html, body { |
| 31 | + background-color: transparent; /* 横屏模式下透明背景,让背景图片可见 */ |
| 32 | + } |
| 33 | + } |
| 34 | + |
28 | 35 | * { |
29 | 36 | margin: 0; |
30 | 37 | padding: 0; |
|
45 | 52 | /* 主容器 */ |
46 | 53 | .app-container { |
47 | 54 | position: relative; |
48 | | - width: 100vw; |
| 55 | + width: 100%; |
49 | 56 | max-width: 583px; |
50 | 57 | min-height: 100vh; /* 最小高度为视口高度 */ |
51 | 58 | background-image: url('bg1.png'); |
|
54 | 61 | background-size: 100% 100%; /* 宽度和高度都填满容器 */ |
55 | 62 | background-attachment: scroll; |
56 | 63 | overflow-y: auto; /* 允许垂直滚动 */ |
57 | | - // padding-bottom: 20px; /* 底部留出空间 */ |
| 64 | + margin: 0 auto; |
58 | 65 | } |
59 | 66 |
|
60 | | - /* 当页面宽度大于583px时,采用固定大小的手机端布局 */ |
| 67 | + /* 桌面端布局 */ |
61 | 68 | @media (min-width: 584px) { |
62 | 69 | .app-container { |
63 | | - width: 583px; /* 固定宽度 */ |
64 | | - margin: 0 auto; /* 居中显示 */ |
| 70 | + width: 100%; /* 全宽度 */ |
| 71 | + max-width: 100%; /* 取消最大宽度限制 */ |
| 72 | + margin: 0; /* 取消居中 */ |
| 73 | + background: transparent; /* 透明背景 */ |
| 74 | + /* 使用 bg2 作为桌面端背景 */ |
| 75 | + background-image: none; /* 移除原 bg1 背景 */ |
| 76 | + height: 100vh; /* 固定高度,确保垂直居中 */ |
| 77 | + overflow: hidden; /* 关闭滚动 */ |
| 78 | + } |
| 79 | + |
| 80 | + /* 桌面端使用 bg2 作为背景 */ |
| 81 | + .app-container::before { |
| 82 | + content: ''; |
| 83 | + position: fixed; |
| 84 | + top: 0; |
| 85 | + left: 0; |
| 86 | + width: 100%; |
| 87 | + height: 100%; |
| 88 | + background-image: url('bg2.png'); |
| 89 | + background-repeat: repeat; /* 平铺填充 */ |
| 90 | + background-size: cover; /* 覆盖整个屏幕,不留白 */ |
| 91 | + background-position: center; |
| 92 | + z-index: -1; |
65 | 93 | } |
66 | 94 |
|
| 95 | + /* 魔法书随页面大小动态缩放,保持宽高比 */ |
67 | 96 | .magic-book { |
68 | | - width: 280px; /* 固定宽度 */ |
69 | | - height: 420px; /* 固定高度 */ |
| 97 | + width: 60vw; /* 随页面宽度动态缩放,放大为原来的 150% */ |
| 98 | + max-width: 600px; /* 最大宽度限制,放大为原来的 150% */ |
| 99 | + height: auto; /* 自动高度,保持宽高比 */ |
| 100 | + aspect-ratio: 2 / 3; /* 宽高比 2:3 */ |
| 101 | + margin: 0 auto; /* 垂直水平居中 */ |
| 102 | + transform: translateY(50px); /* 向下移动 50px */ |
70 | 103 | } |
71 | 104 |
|
| 105 | + /* 魔法书容器也需要保持宽高比 */ |
| 106 | + .book-container { |
| 107 | + height: 100%; |
| 108 | + } |
| 109 | + |
| 110 | + /* 确保魔法书组件垂直水平居中 */ |
| 111 | + .book-section { |
| 112 | + display: flex; |
| 113 | + justify-content: center; |
| 114 | + align-items: center; |
| 115 | + } |
| 116 | + |
| 117 | + /* 翻页动画位移调整 */ |
72 | 118 | .book-container.flipping { |
73 | | - transform: translateX(50%); /* 向右位移50%宽度 */ |
| 119 | + transform: translateX(80px); /* 调整位移 */ |
| 120 | + } |
| 121 | + |
| 122 | + /* 横屏模式下隐藏除魔法书之外的组件 */ |
| 123 | + .header, |
| 124 | + .question-section, |
| 125 | + .btn-container, |
| 126 | + .footer { |
| 127 | + display: none; |
| 128 | + } |
| 129 | + |
| 130 | + |
| 131 | + /* 确保魔法书垂直水平居中显示 */ |
| 132 | + .main-content { |
| 133 | + display: flex; |
| 134 | + justify-content: center; |
| 135 | + align-items: center; |
| 136 | + height: 100vh; |
| 137 | + width: 100%; |
| 138 | + overflow: hidden; /* 关闭横屏模式下的页面滚动 */ |
74 | 139 | } |
75 | 140 | } |
76 | 141 |
|
|
158 | 223 | .main-content { |
159 | 224 | // background: var(--white);// 取消白色圆角矩形背景 |
160 | 225 | border-radius: 25px; |
161 | | - padding: 20px 0 50px 0; |
| 226 | + padding: 40px 20px 60px 20px; |
162 | 227 | // box-shadow: |
163 | 228 | 0 20px 60px rgba(200, 16, 46, 0.15), |
164 | 229 | 0 0 0 1px rgba(200, 16, 46, 0.1); |
165 | 230 | position: relative; |
166 | 231 | overflow: visible; |
| 232 | + max-width: 1200px; /* 限制最大宽度 */ |
| 233 | + margin: 0 auto; /* 居中显示 */ |
| 234 | + } |
| 235 | + |
| 236 | + /* 桌面端内容布局 */ |
| 237 | + @media (min-width: 900px) { |
| 238 | + .main-content { |
| 239 | + display: flex; |
| 240 | + flex-direction: row; |
| 241 | + align-items: center; |
| 242 | + justify-content: center; |
| 243 | + gap: 60px; |
| 244 | + padding: 60px 40px; |
| 245 | + } |
| 246 | + |
| 247 | + .book-section { |
| 248 | + flex: 0 0 auto; |
| 249 | + margin-bottom: 0; |
| 250 | + } |
| 251 | + |
| 252 | + .question-section, |
| 253 | + .btn-container { |
| 254 | + flex: 1; |
| 255 | + max-width: 400px; |
| 256 | + margin-top: 60px; |
| 257 | + } |
| 258 | + |
| 259 | + .question-input { |
| 260 | + font-size: 1.3rem; |
| 261 | + padding: 22px 24px; |
| 262 | + } |
| 263 | + |
| 264 | + .ask-btn { |
| 265 | + width: 320px; |
| 266 | + height: 70px; |
| 267 | + font-size: 1.4rem; |
| 268 | + } |
| 269 | + |
| 270 | + /* 魔法书随页面大小动态缩放,保持宽高比 */ |
| 271 | + .magic-book { |
| 272 | + width: 60vw; /* 随页面宽度动态缩放,放大为原来的 150% */ |
| 273 | + max-width: 600px; /* 最大宽度限制,放大为原来的 150% */ |
| 274 | + height: auto; /* 自动高度,保持宽高比 */ |
| 275 | + aspect-ratio: 2 / 3; /* 宽高比 2:3 */ |
| 276 | + margin: 0 auto; /* 垂直水平居中 */ |
| 277 | + transform: translateY(50px); /* 向下移动 50px */ |
| 278 | + } |
167 | 279 | } |
168 | 280 |
|
169 | 281 | .book-section { |
|
413 | 525 | } |
414 | 526 |
|
415 | 527 | .question-section { |
416 | | - margin-bottom: 40px; |
| 528 | + margin-bottom: 30px; |
417 | 529 | } |
418 | 530 |
|
419 | 531 | .question-label { |
|
562 | 674 |
|
563 | 675 | .footer { |
564 | 676 | text-align: center; |
565 | | - margin-top: 60px; |
| 677 | + margin-top: 70px; |
566 | 678 | color: #ffce7b; |
567 | 679 | font-size: 0.9rem; |
568 | 680 | position: relative; |
|
602 | 714 | } |
603 | 715 |
|
604 | 716 | .magic-book { |
605 | | - height: 480px; /* 宽高比 2:3,320 * 1.5 = 480 */ |
606 | | - max-width: 320px; |
| 717 | + width: 280px; /* 固定宽度,手机端大小 */ |
| 718 | + height: 420px; /* 固定高度,手机端大小 */ |
| 719 | + margin: 0 auto 40px; |
| 720 | + position: relative; |
| 721 | + cursor: pointer; |
607 | 722 | } |
608 | 723 |
|
609 | 724 | .book-container { |
610 | | - height: 480px; |
| 725 | + height: 420px; |
611 | 726 | } |
612 | 727 |
|
613 | 728 | .book-container.flipping { |
|
688 | 803 | <div class="container"> |
689 | 804 | <div class="header"> |
690 | 805 | <img src="title.png" alt="新年答案之书" class="title-image" style="display: block; margin: 0 auto; max-width: 70%; height: auto;"> |
691 | | - <p class="subtitle">提出你的问题,寻找新年的答案...</p> |
| 806 | +<!-- <p class="subtitle">提出你的问题,寻找新年的答案...</p>--> |
692 | 807 | <div class="decorative-line"></div> |
693 | 808 | </div> |
694 | 809 |
|
|
752 | 867 | <li class="book-page"> |
753 | 868 | <div class="book-inner-page"> |
754 | 869 | <div class="inner-page-content" style="font-size: 1.2rem; color: var(--text-dark); font-style: italic;"> |
755 | | - 改变方向 |
| 870 | + |
756 | 871 | </div> |
757 | 872 | </div> |
758 | 873 | </li> |
759 | 874 | <!-- 内页 8 --> |
760 | 875 | <li class="book-page"> |
761 | 876 | <div class="book-inner-page"> |
762 | 877 | <div class="inner-page-content" style="font-size: 1.2rem; color: var(--text-dark); font-style: italic;"> |
763 | | - 放松点 |
| 878 | + |
764 | 879 | </div> |
765 | 880 | </div> |
766 | 881 | </li> |
|
790 | 905 | </div> |
791 | 906 | </div> |
792 | 907 |
|
793 | | - <div class="question-section"> |
| 908 | + <div class="content-right"> |
| 909 | + <div class="question-section"> |
794 | 910 | <!-- <label for="question-input" class="question-label">你的问题</label>--> |
795 | | - <input type="text" id="question-input" class="question-input" placeholder="输入你的问题..." autocomplete="off"> |
796 | | - </div> |
797 | | - |
798 | | - <div class="btn-container"> |
799 | | - <button class="ask-btn" id="ask-btn">获取答案</button> |
800 | | - </div> |
| 911 | + <input type="text" id="question-input" class="question-input" placeholder="输入问题,寻找新年的答案..." autocomplete="off"> |
| 912 | + </div> |
801 | 913 |
|
802 | | - </div> |
| 914 | + <div class="btn-container"> |
| 915 | + <button class="ask-btn" id="ask-btn">获取答案</button> |
| 916 | + </div> |
803 | 917 |
|
804 | | - <div class="footer"> |
805 | | - <p style="margin-top: -52px; font-size: 0.8rem;">记住,答案的力量在于你如何理解它</p> |
806 | | - </div> |
| 918 | + <div class="footer"> |
| 919 | + <p style="margin-top: -52px; font-size: 0.8rem;">记住,答案的力量在于你如何理解它</p> |
| 920 | + </div> |
| 921 | + </div> |
807 | 922 | </div> |
808 | 923 | </div> |
809 | 924 |
|
|
1029 | 1144 | }); |
1030 | 1145 |
|
1031 | 1146 | magicBook.addEventListener('click', function() { |
1032 | | - const question = questionInput.value.trim(); |
| 1147 | + // 检查是否是横屏模式 |
| 1148 | + const isDesktop = window.innerWidth >= 584; |
1033 | 1149 |
|
1034 | | - if (!question) { |
1035 | | - // 如果输入框没有内容,唤起键盘准备输入 |
1036 | | - questionInput.focus(); |
| 1150 | + if (isDesktop) { |
| 1151 | + // 横屏模式下直接播放动画加载答案 |
| 1152 | + desktopGetAnswer(); |
1037 | 1153 | } else { |
1038 | | - // 如果输入框已有内容,执行获取答案的逻辑 |
1039 | | - getAnswer(); |
| 1154 | + // 竖屏模式下保持原操作逻辑 |
| 1155 | + const question = questionInput.value.trim(); |
| 1156 | + if (!question) { |
| 1157 | + questionInput.focus(); |
| 1158 | + } else { |
| 1159 | + getAnswer(); |
| 1160 | + } |
1040 | 1161 | } |
1041 | 1162 | }); |
1042 | 1163 |
|
| 1164 | + // 横屏模式获取答案函数 |
| 1165 | + function desktopGetAnswer() { |
| 1166 | + // 检查是否已经翻页 |
| 1167 | + if (isFlipped) { |
| 1168 | + // 反向翻页回到封面 |
| 1169 | + bookContainer.classList.remove('flipping'); |
| 1170 | + isFlipped = false; |
| 1171 | + return; |
| 1172 | + } |
| 1173 | + |
| 1174 | + // 加载随机答案 |
| 1175 | + const randomIndex = Math.floor(Math.random() * answers.length); |
| 1176 | + const answer = answers[randomIndex]; |
| 1177 | + answerPageContent.textContent = answer; |
| 1178 | + |
| 1179 | + // 播放翻页动画 |
| 1180 | + bookContainer.classList.add('flipping'); |
| 1181 | + isFlipped = true; |
| 1182 | + } |
| 1183 | + |
1043 | 1184 | // 获取答案函数 |
1044 | 1185 | function getAnswer() { |
1045 | 1186 | const question = questionInput.value.trim(); |
|
0 commit comments