| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | id: 587d78a7367417b2b2512ae2 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | title: 通过从左到右淡化元素来创建视觉方向 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | challengeType: 0 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:46:34 +08:00
										 |  |  | videoUrl: 'https://scrimba.com/c/cGJqqAE' | 
					
						
							|  |  |  | forumTopicId: 301054 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | dashedName: create-visual-direction-by-fading-an-element-from-left-to-right | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --description--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | 在本挑战中,我们需要改变动画元素的 `opacity` 属性值,使其在到达屏幕右侧时渐隐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | 在示例动画中,具有渐变背景的圆形元素在 `@keyframes` 为 50% 的节点向右移动。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --instructions--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:42:36 +00:00
										 |  |  | 使用 id 选择器选择 id 为 `ball` 的元素,在 @keyframes 为 `50%` 的节点里添加 `opacity` 属性并设置属性值为 0.1,使其在向右移动时渐隐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --hints--
 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-08 11:20:48 -08:00
										 |  |  | `keyframes` 为 50% 的节点处应设置 `opacity` 属性值为 0.1,以使其渐隐。 | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | ```js | 
					
						
							|  |  |  | assert( | 
					
						
							|  |  |  |   code.match( | 
					
						
							|  |  |  |     /@keyframes fade\s*?{\s*?50%\s*?{\s*?(?:left:\s*?60%;\s*?opacity:\s*?0?\.1;|opacity:\s*?0?\.1;\s*?left:\s*?60%;)/gi | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2018-10-10 18:03:03 -04:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | # --seed--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## --seed-contents--
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ```html | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   #ball { | 
					
						
							|  |  |  |     width: 70px; | 
					
						
							|  |  |  |     height: 70px; | 
					
						
							|  |  |  |     margin: 50px auto; | 
					
						
							|  |  |  |     position: fixed; | 
					
						
							|  |  |  |     left: 20%; | 
					
						
							|  |  |  |     border-radius: 50%; | 
					
						
							|  |  |  |     background: linear-gradient( | 
					
						
							|  |  |  |       35deg, | 
					
						
							|  |  |  |       #ccffff, | 
					
						
							|  |  |  |       #ffcccc | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     animation-name: fade; | 
					
						
							|  |  |  |     animation-duration: 3s; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @keyframes fade { | 
					
						
							|  |  |  |     50% { | 
					
						
							|  |  |  |       left: 60%; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <div id="ball"></div> | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-16 00:37:30 -07:00
										 |  |  | # --solutions--
 | 
					
						
							| 
									
										
										
										
											2020-02-11 15:46:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | ```html | 
					
						
							|  |  |  | <style> | 
					
						
							|  |  |  |   #ball { | 
					
						
							|  |  |  |     width: 70px; | 
					
						
							|  |  |  |     height: 70px; | 
					
						
							|  |  |  |     margin: 50px auto; | 
					
						
							|  |  |  |     position: fixed; | 
					
						
							|  |  |  |     left: 20%; | 
					
						
							|  |  |  |     border-radius: 50%; | 
					
						
							|  |  |  |     background: linear-gradient( | 
					
						
							|  |  |  |       35deg, | 
					
						
							|  |  |  |       #ccffff, | 
					
						
							|  |  |  |       #ffcccc | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     animation-name: fade; | 
					
						
							|  |  |  |     animation-duration: 3s; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @keyframes fade { | 
					
						
							|  |  |  |     50% { | 
					
						
							|  |  |  |       left: 60%; | 
					
						
							|  |  |  |       opacity: 0.1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | </style> | 
					
						
							|  |  |  | <div id="ball"></div> | 
					
						
							|  |  |  | ``` |