如何用 JavaScript 設定文字的陰影效果?


若要設定陰影效果,請在 JavaScript 中使用 textShadow 屬性。

示例

你可以嘗試執行以下程式碼,以透過 JavaScript 返回文字的陰影效果 −

<!DOCTYPE html>
<html>
   <body>
      <button onclick = "display()">Set Text Shadow</button>

      <div id = "myID">
         This is Demo Text! This is Demo Text! This is <br>This is Demo Text! This is Demo Text! This is Demo Text! This is Demo Text!<br> This is Demo Text!<br> This is Demo Text! This is Demo Text! This is Demo Text! This is Demo Text!
      </div>

      <script>
         function display() {
            document.getElementById("myID").style.textShadow = "2px 2px 2px #ff0000,20px 5px 2px #F1F1F1";
         }
      </script>
   </body>
</html>

更新於:2020-6-23

830 次瀏覽

開啟您的 職業

完成課程,獲得認證

開始學習
廣告
© . All rights reserved.