亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不使用顏色混合創建LinearGradient

不使用顏色混合創建LinearGradient

陪伴而非守候 2024-01-18 14:41:22
使用 ,createLinearGradient我們可以根據 中的停止值創建顏色漸變和顏色混合addColorStop。var gradient = ctx.createLinearGradient(0, 0, 0, 400);     gradient.addColorStop(0, 'blue');        gradient.addColorStop(1, 'red');我們是否可以避免顏色混合并根據停止值具有不同的顏色而不使用混合或漸變。createLinearGradient也許這對于任何其他 API都是不可能的?fillRect我知道我們可以使用兩個不同的和來創建它fillStyle。
查看完整描述

1 回答

?
達令說

TA貢獻1821條經驗 獲得超6個贊

我不是 100% 確定你的意思,但如果你想要兩種不同顏色的清晰停止,你可以簡單地將兩種顏色設置在相同的停止位置:


const canvas = document.querySelector("canvas");

const ctx = canvas.getContext("2d");

const grad = ctx.createLinearGradient(0,0,0,150);

// implicit from -Infinity "green"

grad.addColorStop(0.33, "green");

grad.addColorStop(0.33, "yellow"); // same stop as previous color

grad.addColorStop(0.66, "yellow");

grad.addColorStop(0.66, "red");    // same stop as previous color

// implicit to +Infinity "red"

ctx.fillStyle = grad;

ctx.fillRect(0,0,300,150);

<canvas></canvas>


查看完整回答
反對 回復 2024-01-18
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號