🖍️
CSS 排版及動畫效果
  • CSS 排版及動畫效果
  • 1. 簡介
    • 1.1 講者簡介
    • 1.2 課程簡介
    • 1.3 開發工具簡介
  • 2. 棋盤式排版模式 Grid
    • 2.1 基本觀念及術語
    • 2.2 Grid 排版 - Container
    • 2.3 Grid 排版 - Items
  • 3. 多欄排版模式 Column
  • 4. 轉場效果 transition
    • 4.1 第一個 transition
    • 4.2 屬性 transition-property
    • 4.3 期間 transition-duration
    • 4.4 漸變函式 transition-timing-function
    • 4.5 延遲 transition-delay
    • 4.6 transition 縮寫
    • 4.7 練習
  • 5. 動畫效果 animation
    • 5.1 第一個 animation
    • 5.2 關於 keyframes
    • 5.3 同個元素套用多個 animation
    • 5.4 次數 animation-iteration-count
    • 5.5 方向 animation-direction
    • 5.6 延遲 animation-delay
    • 5.7 填滿模式 animation-fill-mode
    • 5.8 播放狀態 animation-play-state
    • 5.9 漸變函式 animation-timing-function
    • 5.10 animation 縮寫
    • 5.11 補充:動畫效果事件(Animation Event)
    • 5.12 練習
  • 6. 作業
  • 7. 第三方動畫效果套件
    • 7.1 Animate.css
    • 7.2 AOS
    • 7.3 CSS Loader
  • 8. 大量練習
  • 9. 其它及參考資料
Powered by GitBook
On this page
  • 練習1:搜尋框 :focus 狀態的轉場效果
  • 練習2:圖片編排 - 文字蓋在圖片上方及滑動
  • 練習3:頁面下滑,置頂區域的呈現
  1. 4. 轉場效果 transition

4.7 練習

Previous4.6 transition 縮寫Next5. 動畫效果 animation

Last updated 1 year ago

練習1:搜尋框 :focus 狀態的轉場效果

指定檔名:search_transition.html

說明:

  • 搜尋框 100px

  • 放大鏡 icon 定位在搜尋框的恰當位置(如圖)。

  • 點擊 focus 狀態的時候,寬度變成 100%,需設定 transition

結果示意:

提供 html:

<input type="text" class="search" placeholder="搜尋..">

搜尋 icon 的圖片路徑:

參考作法:

練習2:圖片編排 - 文字蓋在圖片上方及滑動

指定檔名:text_cover.html

說明:

  • 整個區塊是一個連結,點擊開新分頁。(連到任意網址皆可)

  • 圓角 5px。

  • 「美麗的風景」文字顏色 #FFF,背景色 hsla(0, 0%, 0%, .5),文字大小 .8rem。定位在距離上方 10px、距離左側 0px。

  • 「次要說明」文字,樣式同上,但預設看不到,定位在距離左側 0px、距離下方 0px。

  • 滑鼠移過連結區塊,「次要說明」文字,往上滑出(transition):transform .5s。

結果示意:

提供 html:

<a href="http://tw.yahoo.com" target="_blank" class="card">
  <img src="https://picsum.photos/id/774/500/300">
  <span class="hint_text">美麗的風景</span>
  <div class="other_notes">次要說明次要說明次要說明</div>
</a>

參考作法:

練習3:頁面下滑,置頂區域的呈現

指定檔名:fixed_top_nav.html

結果示意:

提供最上方置頂的那塊 html:

<div class="fixed_top">這是置頂的區域</div>

載入 jQuery :(放在 </body> 結束標籤之前)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

以下程式放在 </body> 結束標籤之前,在上述 jQuery 載入之後:

var header_active = function(){
  
  // 取得使用者滑了多少 px
  var scroll_top = $(window).scrollTop();
  
  // 將 scroll_top 數值放到 p.-pos 內容
  $("p.-pos").html(scroll_top);
  
  
  if(scroll_top >= 100){
    $("div.fixed_top").addClass("-on");
  }else{
    $("div.fixed_top").removeClass("-on");
  }
  
};


$(function(){
  
  // 第三步:偵測頁面滑動時會觸發
  $(window).scroll(function(){
    header_active();
  });
  
});

參考作法:

圖片路徑:

https://alldata.sgp1.digitaloceanspaces.com/images/searchicon.png
https://picsum.photos/id/774/500/300