offsetLeft ဂုဏ်သတ္တိ

offsetLeft ဂုဏ်သတ္တိသည် အရာ၏ ဘယ်ဘက်ရွေ့ရှားမှုကို offsetParent နှင့်ဆက်စပ်၍ ပါရှိသည်။ offsetParent မှ အရာ၏အနားသတ်အထိ အကွာအဝေးကိုပါရှိသည်။

ဝါကျဖွဲ့စည်းပုံ

javascriptအရာ.offsetLeft;

ဥပမာ

အရာ၏ ရွေ့ရှားမှုကို ၎င်း၏ offsetParent နှင့်ဆက်စပ်၍ ရှာကြည့်ရအောင်။

html<div id="parent" style="position: relative;">
  <div id="elem" style="position: absolute; left: 100px"></div>
</div>
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetLeft);

ကုဒ် run ပြီးသောရလဒ်။

javascript100

ဥပမာ

margin အကွာအဝေးများသည် ရွေ့ရှားမှုထဲသို့ ပေါင်းထည့်ခြင်းခံရသည်။

html<div id="parent" style="position: relative;">
  <div id="elem" style="position: absolute; left: 100px; margin: 50px"></div>
</div>
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetLeft);

ကုဒ် run ပြီးသောရလဒ်။

javascript150

ဒါတွေလဲကြည့်ပါ

  • offsetTop ဂုဏ်သတ္တိ၊
    အရာ၏ အပေါ်ဘက်မှ ရွေ့ရှားမှုကိုပါရှိသည်
  • getBoundingClientRect method၊
    အရာ၏ ရွေ့ရှားမှုကိုရှာဖွေသည်