當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


HTML DOM Marquee用法及代碼示例

HTML DOM Marquee Object 用於表示 HTML <marquee> 標簽。我們知道 <marquee> 標簽用於將內容從水平移動到垂直或從左到右或從右到左。

用法

  • 它用於訪問選框標簽。

    document.getElementById("id");  
  • 它用於創建選取框標簽。

    document.createElement("MARQUEE");

屬性值:

  • bgcolor:用於設置或返回 <marquee> 標簽的背景顏色值。
  • direction:它用於設置或返回 <marquee> 標簽的方向屬性的值。
  • loop:它用於設置或返回 <marquee> 標簽的循環屬性的值。
  • height:它用於設置或返回 <marquee> 標簽的高度。
  • width:它用於設置或返回 <marquee> 標簽的高度。
  • hspace:它用於設置或返回 <marquee> 標簽的空格。
  • vspace:它用於設置或返回 <marquee> 標簽的 vspace。

範例1:下麵的 HTML 代碼說明了如何創建選取框對象。

HTML


<!DOCTYPE html>
<html>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
      
    <h2>DOM Marquee Object</h2>
      
    <b>
        Click on the below button to 
        create a marquee object
    </b>
      
    <p></p>
      
    <button onclick="createMarqueObject()">
        Create Marquee Object
    </button>
  
    <script>
        function createMarqueObject() {
            var elementVar = document.createElement("MARQUEE");
            var txt = document.createTextNode(
                "GeeksforGeeks:A computer Science Portal for Geek");
            elementVar.appendChild(txt);
            document.body.appendChild(elementVar);
        }
    </script>
</body>
  
</html>

輸出:

HTML DOM Marquee Object

範例2:下麵的 HTML 代碼說明了如何更改選取框元素的背景顏色和字體大小。

HTML


<!DOCTYPE html>
<html>
  
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksforGeeks
    </h1>
  
    <h2>DOM Marquee Object</h2>
  
    <marquee id="marqueeID">
        GeeksforGeeks:A computer Science
        Portal for Geeks
    </marquee>
    <br><br>
  
    <button onclick="btnClick()">
        Change BackGround Color
    </button>
  
    <script>
        function btnClick() {
            var txt = document.getElementById("marqueeID");
            txt.style.backgroundColor = "green";
            txt.style.fontSize = "25px";
        }
    </script>
</body>
  
</html>

輸出:

HTML DOM Marquee Object

支持的瀏覽器:

  • 穀歌瀏覽器1.0
  • 邊12.0
  • 火狐 65.0
  • Internet Explorer 2.0
  • Opera 7.2
  • 野生動物園 1.2


相關用法


注:本文由純淨天空篩選整理自ManasChhabra2大神的英文原創作品 HTML DOM Marquee Object。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。