CSS scroll-state()

Like container queries; but for stuck, snapped, and overflowing queries.

Chrome 133 မှာ scroll state container queries ကိုစပြီးတော့ မိတ်ဆက်လာတယ် sticky positioning, scroll snap points, scrollable elements ဒီလို state တွေကို CSS ကနေ query လုပ်လို့ ရသွားပါပြီ

Overview

scroll state queries တွေမရှိခင်ကဆိုရင် အပေါ်မှာပြောခဲ့တဲ့ state တွေ ဥပမာ element တစ်ခုသည် sticky ဖြစ်နေသလား၊ scroll area ထဲမှာရှိသေးလား မရှိတော့ဘူးလား၊ overflow ဖြစ်ပြီး scroll လုပ်လို့ရနေတာလား ဆိုတာတွေကို စစ်ဖို့ JavaScript ကနေပဲ လုပ်ရတယ်၊ အခုကျ JavaScript မလိုတော့ဘဲ CSS နဲ့တင် အဆင်ပြေသွားတယ်ပေါ့ scroll state queries တွေအကြောင်းပြောချင်ရင် container queries တွေကိုတော့အရင်ဖတ်ထားဖို့လိုပါတယ်

အဓိကကတော့ scroll state queries သုံးမျိုးရှိမယ်

Stuck state

သူကတော့ element တစ်ခုက အစွန်ဆုံးတစ်ဖက်မှာ stuck ဖြစ်နေတဲ့ အခြေနေ ဆိုလိုတာက sticky ဖြစ်နေတဲ့အချိန်ကို စစ်ဖို့ပါ

Snapped state

သူကတော့ element တစ်ခုက အစွန်တစ်ဘက်ဘက်ကိုဝင်သွားရင် ဆိုလိုတာက hidden ဖြစ်သွားတဲ့ အခြေနေကို စစ်ဖို့ပါ

Scrollable state

သူကတော့ element သည် scrollable ဖြစ်နေလား မဖြစ်နေသလား ဆိုလိုတာက overflow:scroll ဖြစ်နေတဲ့အခြေနေဟုတ်မဟုတ်ကို စစ်ဖို့ဖြစ်ပါတယ်

scroll driven animations နဲ့ scroll state queries တွေကိုသုံးပြီး ဖန်တီးတဲ့ animations တွေနဲ့က ကွာခြားမှုရှိပါတယ်၊ အဓိကက timing နဲ့ context ကွာပါလိမ့်မယ်၊ scroll state queries တွေက scroll driven animations တွေထက်ပိုပြီးတော့ control လုပ်ခွင့်ပေးနိုင်တဲ့သဘောရှိပါတယ်

အောက်မှာ နမူနာကြည့်လို့ရပါတယ်

(left) scroll-state() triggered animation, (right) scroll-driven animation

Scroll-state query ဘယ်လိုရေးရသလဲ

Scroll-state query ဆိုတာ ပြောရရင် container query တစ်ခုထပ်တိုးတဲ့သဘောပဲ container type ထဲမှာ နောက်တစ်မျိုးတိုးလာတာပေါ့

ပိုကောင်းတာကတော့ browser တိုင်းမှာ မရသေးတာဖြစ်လို့ @support နဲ့စစ်ပေးထားသင့်တယ်

Use Cases

Add a shadow when stuck

Activate the current stuck header

Visually boost the snapped item

Show the caption for the snapped item

Animating in slide elements

Indicate scroll with shadow

Arrow prompt

Return to top

Reference:https://developer.chrome.com/blog/css-scroll-state-queries

Last updated