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


HTML DOM Window screenY屬性用法及代碼示例

Window screenY 屬性用於返回‘y’ 或窗口相對於屏幕的垂直坐標。它返回一個數字,表示窗口相對於屏幕的垂直距離(以像素為單位)。

用法:

window.screenY

以下示例程序旨在說明 window.screenY 屬性:

檢查窗口相對於屏幕的 Y 坐標。

HTML


<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
      Window screenY Property in HTML 
    </title> 
    <style> 
        h1 { 
            color: green; 
        } 
          
        h2 { 
            font-family: Impact; 
        } 
          
        body { 
            text-align: center; 
        } 
    </style> 
</head> 
  
<body> 
  
    <h1>GeeksforGeeks</h1> 
    <h2>Window screenY  Property</h2> 
  
    <p> 
      For returning the Y coordinates of a window  
      relative to the screen, double click the "Check  
      Y Coordinate" button:  
    </p> 
  
    <button ondblclick="coordinate()"> 
      Check Y Coordinate 
    </button> 
  
    <script> 
        function coordinate() { 
            var Y = window.open("", "myWindow"); 
            Y.document.write 
                    ("<p>Welcome to my Window"); 
            Y.document.write 
            ("<br>Y Coordinate : " + Y.screenY + "</p>"); 
        } 
    </script> 
  
</body> 
  
</html>                    

輸出:

單擊按鈕後

支持的瀏覽器:支持的瀏覽器窗紗Y 屬性列出如下:

  • 穀歌瀏覽器 1 及以上版本
  • 邊 12 及以上
  • 火狐瀏覽器1及以上版本
  • Internet Explorer 9 及更高版本
  • Opera 12.1 及以上版本
  • Safari 1 及以上版本


相關用法


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