လုပ်နည်း - Smooth Scroll
CSS ဖြင့် ချောမွေ့သော scrolling effect ဖန်တီးနည်းကို လေ့လာပါ။
Smooth Scrolling
အပိုင်း ၁
"ချောမွေ့သော" scrolling effect ကိုကြည့်ရှုရန် link ကိုနှိပ်ပါ။
အောက်ဖော်ပြပါ အပိုင်း 2 သို့ ချောမွေ့စေရန် Me ကို နှိပ်ပါ။မှတ်ချက်- ချောမွေ့သော လှိမ့်ခြင်းကို ဖယ်ရှားရန် scroll-behavior property ကို ဖယ်ရှားပါ။
Smooth Scrolling
scroll-behavior: smooth
စာမျက်နှာတစ်ခုလုံးအတွက် ချောမွေ့စွာ လှိမ့်နိုင်စေရန် <html> ဒြပ်စင်သို့ ထည့် ပါ (မှတ်ချက်- ၎င်းကို သီးခြားဒြပ်စင်/scroll container တွင် ထည့်ရန်လည်း ဖြစ်နိုင်သည်)။
ဥပမာ
html {
scroll-behavior: smooth;
}
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် scroll-behavior property ကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးပါသည်။
Property | |||||
---|---|---|---|---|---|
scroll-behavior | 61.0 | 79.0 | 36.0 | 14.0 | 48.0 |
Cross-browser ဖြေရှင်းချက်
ပိုင်ဆိုင်မှု ကိုမပံ့ပိုးသော ဘရောက်ဆာများအတွက်၊ ဘရောက်ဆာအားလုံးအတွက်အသုံးပြုနိုင်မည့်ဖြေရှင်းချက်တစ်ခုဖန်တီးရန် scroll-behavior
JavaScript သို့မဟုတ် jQuery ကဲ့သို့သော JavaScript စာကြည့်တိုက်ကိုသင်အသုံးပြုနိုင်သည်-
ဥပမာ
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Add smooth scrolling to all
links
$("a").on('click', function(event) {
// Make sure this.hash
has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
event.preventDefault();
//
Store hash
var hash = this.hash;
// Using jQuery's animate() method
to add smooth page scroll
// The optional number (800) specifies the number
of milliseconds it takes to scroll to the specified area
$('html,
body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
} // End if
});
});
</script>
အကြံပြုချက်- ကျွန်ုပ်တို့၏ CSS ရည်ညွှန်းချက်ရှိ လှိမ့်ပုံ-အပြုအမူဆိုင်ရာ ပိုင်ဆိုင်မှုအကြောင်း ပိုမိုဖတ်ရှုပါ- CSS scroll-behavior Property .