HTML
 Computer >> コンピューター >  >> プログラミング >> HTML

HTMLウィンドウscreenXプロパティ


HTMLウィンドウscreenXプロパティは、画面を基準にしたウィンドウの水平座標を返します。すべてのブラウザでサポートされています。

構文

以下は構文です-

window.screenX

HTMLウィンドウscreenXプロパティの例を見てみましょう-

<!DOCTYPE html>
<html>
<style>
   body {
      color: #000;
      height: 100vh;
      background-color: #8BC6EC;
      background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%);
      text-align: center;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
   .show {
      font-size: 1.2rem;
   }
</style>
<body>
<h1>HTML Window screenX Property Demo</h1>
<button onclick="display()" class="btn">Show screenX value</button>
<div class="show"></div>
<script>
   function display() {
      document.querySelector('.show').innerHTML = 'The horizontal coordinate of the window relative to the screen is: ' + window.screenX + 'px';
   }
</script>
</body>
</html>

出力

HTMLウィンドウscreenXプロパティ

「screenX値を表示」ボタンをクリックして、画面に対するウィンドウの水平座標を表示します。

HTMLウィンドウscreenXプロパティ


  1. HTMLDOMウィンドウのframeElementプロパティ

    HTML DOMウィンドウのframeElementプロパティは、、、などの埋め込みウィンドウに対応するHTML要素を返します。 構文 以下は構文です- ウィンドウ埋め込み要素を返す window.frameElement 例 HTMLDOMウィンドウのframeElementプロパティの例を見てみましょう- <!DOCTYPE html> <html> <head> <title>HTML DOM Window frameElement</title> <style>    * {  

  2. HTMLDOMウィンドウの閉じたプロパティ

    HTML DOMウィンドウのclosedプロパティは、ウィンドウが閉じているかどうかに対応するブール値を返します。 構文 以下は構文です- ブール値を返す window.closed 例 HTMLDOMウィンドウの閉じたプロパティの例を見てみましょう- <!DOCTYPE html> <html> <head> <title>HTML DOM Window closed</title> <style>    * {       padding: 2px;