CSS ကို JavaScript ဖြင့် ပြောင်းလဲနိုင်သော ကိန်းရှင်များ
JavaScript ဖြင့် Variable များကိုပြောင်းလဲပါ။
CSS variable များသည် DOM သို့ ဝင်ရောက်ခွင့်ရှိသည်၊ ဆိုလိုသည်မှာ ၎င်းတို့ကို JavaScript ဖြင့် ပြောင်းလဲနိုင်သည်။
ဤသည်မှာ ယခင်စာမျက်နှာများတွင် အသုံးပြုခဲ့သည့် ဥပမာမှ --blue variable ကို ပြသရန်နှင့် ပြောင်းလဲရန် script တစ်ခုကို ဖန်တီးနိုင်ပုံ ဥပမာတစ်ခုဖြစ်သည်။ လက်ရှိတွင် JavaScript နှင့် မရင်းနှီးပါက စိတ်မပူပါနှင့်။ ကျွန်ုပ်တို့၏ JavaScript Tutorial တွင် JavaScript အကြောင်းပိုမိုလေ့လာသင်ယူနိုင်သည် -
ဥပမာ
<script>
// Get the root element
var r = document.querySelector(':root');
// Create a function for getting a variable value
function
myFunction_get() {
// Get the styles (properties and values) for the
root
var rs = getComputedStyle(r);
// Alert the value of
the --blue variable
alert("The value of --blue is: " +
rs.getPropertyValue('--blue'));
}
// Create a function for setting a
variable value
function myFunction_set() {
// Set the value of
variable --blue to another value (in this case "lightblue")
r.style.setProperty('--blue', 'lightblue');
}
</script>
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် လုပ်ဆောင်ချက်ကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်
var()
။
Function | |||||
---|---|---|---|---|---|
var() | 49.0 | 15.0 | 31.0 | 9.1 | 36.0 |
CSS var() လုပ်ဆောင်ချက်
Property | Description |
---|---|
var() | Inserts the value of a CSS variable |