HTML canvas addColorStop() နည်းလမ်း
ဥပမာ
ထောင့်မှန်စတုဂံအတွက် ဖြည့်စွက်ပုံစံအဖြစ် အနက်မှ အဖြူသို့ သွားသည့် gradient ကို သတ်မှတ်ပါ-
JavaScript-
var c = document.getElementById('myCanvas');
var ctx = c.getContext('2d');
var grd = ctx.createLinearGradient(0, 0, 170, 0);
grd.addColorStop(0, "black");
grd.addColorStop(1, "white");
ctx.fillStyle = grd;
ctx.fillRect(20, 20, 150, 100);
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
addColorStop() | Yes | 9.0 | Yes | Yes | Yes |
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
addColorStop() နည်းလမ်းသည် gradient object တစ်ခုရှိ အရောင်များနှင့် အနေအထားကို သတ်မှတ်ပေးပါသည်။
addColorStop() နည်းလမ်းကို createLinearGradient() သို့မဟုတ် createRadialGradient( ) နှင့် တွဲသုံး ပါသည်။
မှတ်ချက်- gradient တစ်ခုပြောင်းရန် addColorStop() နည်းလမ်းကို အကြိမ်ပေါင်းများစွာ ခေါ်နိုင်သည်။ gradient အရာဝတ္ထုများအတွက် ဤနည်းလမ်းကို ချန်လှပ်ထားပါက၊ gradient ကို မြင်နိုင်မည်မဟုတ်ပေ။ မြင်နိုင်သော gradient ရှိရန် အနည်းဆုံး အရောင်မှတ်တိုင်တစ်ခု ဖန်တီးရန် လိုအပ်သည်။
JavaScript syntax- | gradient .addColorStop( ရပ် ၊ အရောင် ); |
---|
ကန့်သတ်တန်ဖိုးများ
Parameter | Description | Play it |
---|---|---|
stop | A value between 0.0 and 1.0 that represents the position between start and end in a gradient | |
color | A CSS color value to display at the stop position |
နောက်ထပ် ဥပမာများ
ဥပမာ
addColorStop() နည်းလမ်းများစွာဖြင့် gradient ကို သတ်မှတ်ပါ-
JavaScript-
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var grd = ctx.createLinearGradient(0, 0, 170, 0);
grd.addColorStop(0, "black");
grd.addColorStop("0.3", "magenta");
grd.addColorStop("0.5", "blue");
grd.addColorStop("0.6", "green");
grd.addColorStop("0.8", "yellow");
grd.addColorStop(1, "red");
ctx.fillStyle = grd;
ctx.fillRect(20, 20, 150, 100);
❮ HTML Canvas အကိုးအကား