如何在透過捲軸來建立漸變的背景顏色?
要建立在滾動時漸變的背景顏色,程式碼如下 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 250vh;
color: white;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(
141deg,
#a47dff 0%,
#4e28a7 40%,
#22053d 65%,
#72a4ff 75%
);
}
</style>
</head>
<body>
<h1>Change Background Gradient on Scroll Example</h1>
<p style="font-size: 30px;">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, laborum minus? Vero accusantium laborum quas cum, sed obcaecati quibusdam dignissimos.
</p>
<h2 style="position:fixed;">Scroll to see the effect.</h2>
</body>
</html>輸出
上述程式碼將產生以下輸出 −

滾動時,漸變將從深藍色變為淺藍色 −

廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP