# 8. 大量練習

## 練習 1：CSS Animation Loading Icon

指定檔案： `animation_loading_icon.html`\
說明：

* 一個 div，寬高都是 50px。
* 上邊框比較深的紅色 `hsla(0, 100%, 50%, 1)`，其它邊框比較淺的紅色 `hsla(0, 50%, 80%, .5)`。
* 圓角 50%。
* 寫一個 css animation 動畫效果，如下「結果示意」。

提供 html：

```markup
<div class="loading_icon"></div>
```

結果示意：

{% embed url="<https://youtu.be/J49khgxJ6bs>" %}

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/zYxyxmv>" %}

## 練習 2：元素固定螢幕右側，點擊滑出

指定檔名：`fixed_right_sidebar.html`

說明：

* 做一個固定於螢幕右側的介面，點擊按鈕後可以像抽屜那樣的展開、關閉。
* 展開、關閉，需加上 `transition` 做過場效果。

提供 JS，在 `</body>` 結束標籤之前放入以下原始碼：

```markup
<!-- 載入 jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  // DOM 載入完成之後
  $(function(){

    // 點擊
    $("button.btn_drawer").on("click", function(){
      // -open 的樣式切換
      $(this).closest("div.right_sidebar").toggleClass("-open");
    });

  });
</script>
```

結果示意：

{% embed url="<https://youtu.be/bFKKsDJ04Xk>" %}

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/abzMRgp>" %}

## 練習 3：內容的淡入淡出

指定檔名：`content_fadein_fadeout.html`

說明：

* 各自的按鈕，以淡入淡出切換內容的出現。
* 只需要修改 css 的部份即可。

提供 html：

```markup
<button type="button" class="btn1">按鈕1：出現內容1的部份</button>
<button type="button" class="btn2">按鈕2：出現內容2的部份</button>

<div class="content_container">
  <div class="content1 -on"><img src="https://via.placeholder.com/300x300"><br><a href="https://tw.yahoo.com" target="_blank">內容 1：yahoo 連結</a></div>
  <div class="content2"><img src="https://via.placeholder.com/500x500"><br><a href="https://www.google.com" target="_blank">內容 2：google 連結</a></div>
</div>
```

提供 CSS：

```css
div.content_container{
  position: relative;
  border: 1px solid black;
  width: 100%;
}
div.content1, div.content2{
  /* 預設的定位 */
  position: absolute;
  top: 0;
  left: 0;
  
  /* 寫 opacity、z-index 的 css */
  
  /* 寫轉場的 CSS(針對 opacity) */
  
}

/* 該區塊出現時，修改相關樣式 */
div.content1.-on, div.content2.-on{
  /* 寫 CSS */
}
```

提供 JS，在 `</body>` 之前，放入以下原始碼：

```markup
<!-- 載入 jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
  $(function(){
    
    // 點擊按鈕1
    $("button.btn1").on("click", function(){
      // div.content1 和 div.content2 都移除 -on 樣式
      $("div.content1, div.content2").removeClass("-on");
      
      // div.content1 加上 -on 樣式
      $("div.content1").addClass("-on");
    });
    
    // 點擊按鈕2
    $("button.btn2").on("click", function(){
      // div.content1 和 div.content2 都移除 -on 樣式
      $("div.content1, div.content2").removeClass("-on");
      
      // div.content2 加上 -on 樣式
      $("div.content2").addClass("-on");
    });
    
  });
</script>
```

結果示意：

{% embed url="<https://youtu.be/LFmkd4p8PLQ>" %}

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/GRgLBRd>" %}

## 練習 4：次選單淡入淡出

指定檔名：`submenu_fadein_fadeout.html`

結果示意：

{% embed url="<https://youtu.be/8KetZGnnLjs>" %}

提供 html：

```markup
<div class="div_block">
  <p class="para">有次選單</p>
  <div class="inner_block">
    <ul>
      <li><a href="https://tw.yahoo.com" target="_blank">項目一</a></li>
      <li><a href="https://tw.yahoo.com" target="_blank">項目二</a></li>
      <li><a href="https://tw.yahoo.com" target="_blank">項目三</a></li>
    </ul>
  </div>
</div>


<div>
  <p>下方內容</p>
  <img src="https://picsum.photos/seed/picsum/200/300">
</div>
```

參考這個 codepen，沒有淡入淡出的方式：

{% embed url="<https://codepen.io/carlos411/pen/JjYGYbx>" %}

改成淡入淡出。

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/xxwKqWQ>" %}

## 參考

### 練習 1：彩色邊框旋轉

指定檔名：`color_border_rotate.html`

說明：

* 做一個區塊彩色邊框的旋轉。

提供 html：

```markup
<div class="rainbow">
	彩色邊框旋轉
</div>
```

提供部份 CSS：

```css
@keyframes rotation{
  0% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  100% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

div.rainbow{
  width: 200px;
  height: 100px;
  display: inline-block;
  padding: 10px;
  
  /*border: 1px solid red;*/
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}
/* 這個區塊做出四個背景色 */
div.rainbow::before{
  content: "";
  display: inline-block;
  width: 230%;
  height: 230%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(0deg);
  /*border: 1px solid blue;*/
  z-index: -2;
  
  background-image: linear-gradient(green, green), linear-gradient(blue, blue), linear-gradient(purple, purple), linear-gradient(orange, orange);
  background-size: 50% 50%;
  background-position: 0% 0%, 100% 0%, 100% 100%, 0% 100%;
  background-repeat: no-repeat;
}

div.rainbow::after{
  content: "";
  display: block;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: -1;
  background-color: white;
  /*border: 1px solid brown;*/
}
```

預設的樣式：

![預設樣式](/files/-Lzf6G5cktc4ce3QFebZ)

完成結果示意：

{% embed url="<https://youtu.be/omll3yeC388>" %}

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/BayEyoj>" %}

### 練習 2：水效果

指定檔名：`water_effect.html`

提供 html：

```markup
<div class="circle">
  <div class="wave"></div>
</div>
```

提供以下部份 css：

```css
@keyframes water{
	0%{
		transform: translate(-50%, -70%) rotate(0deg);
	}
	100%{
		transform: translate(-50%, -75%) rotate(360deg);
	}
}

body{
  margin: 0;
}
* {
  box-sizing: border-box;
}

.circle{
  display: inline-block;
  width: 150px;
	height: 150px;
  
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	
  
	border: 5px solid white; /* black */
	box-shadow: 0 0 0 5px #4973ff; /* 外圍藍色 */
	border-radius: 50%;
}

.wave{
	position: relative;
	width: 100%;
	height: 100%;
	background: #4973ff;
	border-radius: 50%;
	box-shadow: 0 0 50px hsla(0, 0%, 0%, .5) inset;
}

.wave::before{
	content: '';
	display: inline-block;
	position: absolute;
	width: 200%;
	height: 200%;
	top: 0;
	left: 50%;
  border-radius: 0%;
  
  transform: translate(-50%, -70%) rotate(0deg);
	background: red;
}
```

預設的樣式：

![預設狀態](/files/-Lzf58BGwA72yUAgIuEy)

完成結果示意：

{% embed url="<https://youtu.be/NlAsreQI_b4>" %}

參考作法：

{% embed url="<https://codepen.io/carlos411/pen/ExaJpOw>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.webmix.cc/css-animation/8.-da-liang-lian-xi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
