html multiply属性,html - Test if browser supports "multiply" for globalCompositeOperation canvas prope...

该博客介绍了一种检测浏览器是否支持特定全局组合操作(globalCompositeOperation)的方法。通过设置新的模式并检查当前模式是否匹配,可以轻松判断浏览器是否支持所给模式。示例代码展示了如何创建一个函数来设置并检查这种模式,并在Chrome/macOS上测试了几个例子,包括有效和无效的模式设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Just as many operations on the context, a wrong input to globalCompositeOperation is just ignored, so it's very easy to see if a given mode is supported : just set it, then read the current mode to check it's the one you provided.

So just to be clear, you could use some function like this one :

// setCompositeMode : sets the globalCompositeOperation on provided context.

// return true if mode is supported, false otherwise.

function setCompositeMode(ctx, newMode) {

ctx.globalCompositeOperation = newMode;

return ( ctx.globalCompositeOperation == newMode ) ;

}

Just a small example :

var cv=document.createElement('canvas');

var ctx= cv.getContext('2d');

console.log(" Current (default) composite mode : " + ctx.globalCompositeOperation ) ;

console.log("setting 'destination-in'.");

ctx.globalCompositeOperation = 'destination-in';

console.log(" composite mode : " + ctx.globalCompositeOperation ) ;

console.log("setting 'multiply'.");

ctx.globalCompositeOperation = 'multiply';

console.log(" composite mode : " + ctx.globalCompositeOperation ) ;

console.log("setting 'i-don-t-exist' .");

ctx.globalCompositeOperation = 'i-don-t-exist';

console.log(" composite mode : " + ctx.globalCompositeOperation ) ;

Output (on Chrome/mac OS, supporting multiply) :

" Current (default) composite mode : source-over"

"setting 'destination-in'."

" composite mode : destination-in"

"setting 'multiply'."

" composite mode : multiply"

"setting 'i-don-t-exist' ."

" composite mode : multiply"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值