Window scrollX
ဥပမာ ၁
အကြောင်းအရာကို 100 pixels ဖြင့် လှိမ့်ပြီး scrollX နှင့် scrollY ကို သတိပေးပါ-
window.scrollBy(100, 100);
alert(window.scrollX + window.scrollY);
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
ပိုင်ဆိုင်မှုသည် ဝင်းဒိုး ၏ scrollX
ဘယ်ဘက်အပေါ်ထောင့်မှ စာရွက်စာတမ်းတစ်ခုရွှေ့ထားသော pixels များကို ပြန်ပေးသည်။
scrollX
ပိုင်ဆိုင်မှုသည် ဖတ်ရန်သာဖြစ်သည် ။
မှတ်ချက်
ပိုင်ဆိုင်မှု သည် scrollX
ပိုင်ဆိုင်မှုနှင့် ညီသည်
pageXOffset
။
ဘရောက်ဆာ ဖြတ်ကျော် လိုက်ဖက်မှု အတွက်၊ window.scrollX အစား window.pageXOffset ကို သုံးပါ။
ကိုလည်းကြည့်ပါ-
အထားအသို
window.scrollX
သို့မဟုတ် ရုံ-
scrollX
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
နံပါတ်တစ်ခု | ပြတင်းပေါက်၏ ဘယ်ဘက်အပေါ်ထောင့်မှ စာရွက်စာတမ်းကို ရွှေ့ထားသော pixels အရေအတွက်။ |
နောက်ထပ် ဥပမာများ
စေးကပ်နေသော လမ်းကြောင်းပြဘားတစ်ခု ဖန်တီးပါ-
// Get the navbar
const navbar = document.getElementById("navbar");
// Get the offset position of the navbar
const sticky = navbar.offsetTop;
// Add the sticky class to the navbar when you reach its scroll position. Remove the sticky class when you leave the scroll position.
function myFunction() {
if (window.scrollY >= sticky) {
navbar.classList.add("sticky")
}
else {
navbar.classList.remove("sticky");
}
}
Browser ပံ့ပိုးမှု
window.scrollX
ဘရောက်ဆာအားလုံးတွင် ထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |