我在堆栈上创建了这段代码:
function increase_brightness(hex, percent){
var r = parseInt(hex.substr(1, 2), 16),
g = parseInt(hex.substr(3, 2), 16),
b = parseInt(hex.substr(5, 2), 16);
return '#' +
((0|(1<<8) + r + (256 - r) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + g + (256 - g) * percent / 100).toString(16)).substr(1) +
((0|(1<<8) + b + (256 - b) * percent / 100).toString(16)).substr(1);
}
有谁知道如何完全相反?
函数decreas_brightness(){}
我的意思是
答案 0 :(得分:1)
您的代码来自JavaScript Calculate brighter colour。根据评论,以下更改应使其降低亮度:
function decrease_brightness(hex, percent){
var r = parseInt(hex.substr(1, 2), 16),
g = parseInt(hex.substr(3, 2), 16),
b = parseInt(hex.substr(5, 2), 16);
return '#' +
((0|(1<<8) + r * (100 - percent) / 100).toString(16)).substr(1) +
((0|(1<<8) + g * (100 - percent) / 100).toString(16)).substr(1) +
((0|(1<<8) + b * (100 - percent) / 100).toString(16)).substr(1);
}