如何在透過捲軸來建立漸變的背景顏色?


要建立在滾動時漸變的背景顏色,程式碼如下 −

示例

 即時演示

<!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>

輸出

上述程式碼將產生以下輸出 −

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

更新日期: 08-May-2020

396 檢視數

開啟你的 職業生涯

透過完成課程來獲取認證

開始
廣告
© . All rights reserved.