2025 年新年快樂 |使用 HTML、CSS 和 JavaScript 設計新年賀卡

通過我們使用 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;
  }
登錄后免費查看全文
立即登錄
App下載
技術鄰APP
工程師必備
  • 項目客服
  • 培訓客服
  • 平臺客服

TOP

1
1