2025 年新年快乐 |使用 HTML、CSS 和 JavaScript 设计新年贺卡
1月1日 浏览:785
通过我们使用 HTML、CSS 和 JavaScript 的新年快乐贺卡设计教程,探索创意与技术的完美结合。阅读分步指南,制作视觉上令人惊叹的互动式新年贺卡,打造难忘的庆祝活动。提升您的 Web 开发技能,同时以时尚的方式传播欢乐和愿望。
先决条件:CSS
方法
- W创建包含标题、倒数计时器和庆祝元素的响应式布局。
- 为装饰背景(月亮、云彩、城市景观)添加 SVG 元素
- 定义具有深色主题的完整页面布局,并为月亮、云和文本元素定义动画。
- 将关键帧用于动画,如浮云、脉动的月亮和庆祝的标题颜色过渡。
- 包括浮动表情符号及其动画的样式。
- 使用 getElementById 检索 HTML 元素。
- 设置目标日期(下一个元旦)。
- 计算时差并动态显示天、小时、分钟和秒。
- 使用 setInterval 每秒更新一次倒计时。
- 到达目标日期时:将标题更改为庆祝消息。
- 添加浮动表情符号和庆祝文字动画。
- 使用 clearInterval 停止倒计时。随机生成不同屏幕位置和大小的 emoji。
- 使用 CSS 动画使它们向上浮动,并在延迟后将其删除。
html, body { height: 100%; } body { background-color: #000e31; color: #fff; font-family: "Courier New", Courier, monospace; margin: 0; padding: 0; z-index: 0; } /* Count down code */ @-webkit-keyframes cd-flowin { 0% { opacity: 0; -webkit-transform: translate(-50%, -50%) scale(0); transform: translate(-50%, -50%) scale(0); } 100% { opacity: 1; -webkit-transform: translate(-50%, -50%) scale(1); transform: translate(-50%, -50%) scale(1); } } @keyframes cd-flowin { 0% { opacity: 0; -webkit-transform: translate(-50%, -50%) scale(0); transform: translate(-50%, -50%) scale(0); } 100% { opacity: 1; -webkit-transform: translate(-50%, -50%) scale(1); transform: translate(-50%, -50%) scale(1); } } @-webkit-keyframes cd-new-year-title { 0% { color: red; } 50% { color: blue; } 100% { color: green; } } @keyframes cd-new-year-title { 0% { color: red; } 50% { color: blue; } 100% { color: green; } } @-webkit-keyframes bg-move-cloud { 0% { left: -250px; } 100% { left: 105%; } } @keyframes bg-move-cloud { 0% { left: -250px; } 100% { left: 105%; } } @-webkit-keyframes bg-pulse-moon { 0% { -webkit-transform: scale(1); transform: scale(1); } 100% { -webkit-transform: scale(1.15); transform: scale(1.15); } } @keyframes bg-pulse-moon { 0% { -webkit-transform: scale(1); transform: scale(1); } 100% { -webkit-transform: scale(1.15); transform: scale(1.15); } } #cd { -webkit-animation: cd-flowin 4s ease 1s forwards; animation: cd-flowin 4s ease 1s forwards; display: inline-block; left: 50%; opacity: 0; position: fixed; text-align: center; top: 50%; width: 90%; max-width: 500px; z-index: 2; } #cd .cd__title { color: #ebebeb; font-family: emoji; font-size: 2.2em; font-weight: 700; -webkit-transition: all 1s; transition: all 1s; } #cd .cd__title.cd__title--newyear { -webkit-animation: cd-new-year-title 3s ease alternate infinite; animation: cd-new-year-title 3s ease alternate infinite; } #cd .cd__ele { -webkit-box-sizing: border-box; box-sizing: border-box; color: #fff; display: inline-block; padding: 5% 3.5%; } #cd .cd__ele .cd__ele__value { display: block; font-size: 3.1em; } #cd .cd__ele .cd__ele__name { font-size: 0.85em; font-style: italic; } #cd .cd__ele--secs { color: #57a300; } #cd .cd__timetil { margin-top: 2%; } /* --< Background >-- */ #bg { height: 100%; left: 0; overflow: hidden; position: fixed; right: 0; width: 100%; z-index: 1; } #bg * { position: fixed; } #bg__moon { -webkit-animation: bg-pulse-moon 4s linear 0s alternate infinite; animation: bg-pulse-moon 4s linear 0s alternate infinite; right: 2%; top: 2%; } #bg__grass { bottom: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%); } #bg__city { bottom: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%); } #bg__cloud1 { -webkit-animation: bg-move-cloud 48s linear -12s alternate infinite; animation: bg-move-cloud 48s linear -12s alternate infinite; top: 9%; } #bg__cloud2 { -webkit-animation: bg-move-cloud 60s linear -78s alternate infinite; animation: bg-move-cloud 60s linear -78s alternate infinite; top: 23%; } #bg__cloud3 { -webkit-animation: bg-move-cloud 80s linear -78s alternate infinite; animation: bg-move-cloud 80s linear -78s alternate infinite; top: 15%; } .celebrate { font-size: 2em; margin-top: 10px; animation: float 1.5s ease-in-out infinite, zoom 2s ease-in-out infinite; } @keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } } @keyframes zoom { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } } @keyframes floatUp { 0% { opacity: 0; transform: translateY(50px); } 50% { opacity: 1; } 100% { opacity: 0; transform: translateY(-500px); } } .floating-emoji { position: fixed; bottom: -50px; /* Start below the viewport */ font-size: 2.5em; animation: floatUp 5s ease-in-out forwards; z-index: 9999; pointer-events: none; }
点赞 评论 收藏