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

HTMLDOMoffsetTopプロパティ


HTML DOM offsetTopプロパティは、親要素の上面を基準にした、指定された要素の最上部の位置に対応する数値を返します。

以下は構文です-

数値をピクセル(px)で返す

HTMLelement.offsetTop

ここで、戻り値は-

に対応します
  • 指定された要素の上部の位置とマージン
  • 親要素の上部のパディング、スクロールバー、境界線、および余白

HTML DOM offsetTopの例を見てみましょう プロパティ-

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM offsetTop</title>
<style type="text/css">
   #picForm {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
   }
   #containerDiv {
      margin: 0 auto;
   }
</style>
</head>
<body>
   <form id="picForm">
      <fieldset>
         <legend>HTML-DOM-offsetTop</legend>
         <div id="containerDiv">
            <img id="image" src="https://www.tutorialspoint.com/compiler_design/images/compiler-design-mini-logo.jpg">
         </div>
         <input type="button" onclick="getHeight()" value="Get offsetTop">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
<script>
   var divDisplay = document.getElementById("divDisplay");
   var picForm = document.getElementById("picForm");
   var containerDiv = document.getElementById("containerDiv");
   function getHeight() {
      // window.getComputedStyle() gets the computed css
      var style = window.getComputedStyle(picForm);
      var style2 = window.getComputedStyle(document.body);
      divDisplay.innerHTML = 'Top Offset of form: '+picForm.offsetTop+'px';
      divDisplay.innerHTML += '<br>Top position of Child(form): '+style.Top;
      divDisplay.innerHTML += '<br>Top margin of Child(form): '+style.marginTop;
      divDisplay.innerHTML += '<br>Top padding of Parent(body): '+style2.paddingTop;
      divDisplay.innerHTML += '<br>Top border of Parent(body): '+style2.borderTopWidth;
      divDisplay.innerHTML += '<br>Top margin of Parent(body): '+style2.marginTop;
   }
</script>
</body>
</html>

出力

ボタンをクリックする前に-

HTMLDOMoffsetTopプロパティ

[オフセットトップを取得]をクリックした後 ’ボタン-

HTMLDOMoffsetTopプロパティ


  1. HTMLDOMoffsetLeftプロパティ

    HTML DOM offsetLeftプロパティは、親要素の左側を基準にした、指定された要素の左側の位置に対応する数値を返します。 以下は構文です- 数値をピクセル(px)で返す HTMLelement.offsetLeft ここで、戻り値は-に対応します 指定された要素の左側の位置とマージン 親要素の左側のパディング、スクロールバー、境界線、および余白 HTML DOM offsetLeftの例を見てみましょう プロパティ- 例 <!DOCTYPE html> <html> <head> <title>HTML DOM offse

  2. HTMLDOMビデオtextTracksプロパティ

    HTML DOM Video textTracksプロパティは、ビデオのテキストトラックに関する情報を含むTextTrackListオブジェクトを返します。 構文 以下は構文です- TextTracksListオブジェクトを返す mediaObject.textTracks ビデオtextTracksの例を見てみましょう プロパティ- 例 <!DOCTYPE html> <html> <head> <title>HTML DOM Video textTracks</title> <style>   &nbs