js 求两个颜色之间的渐变值

/**
	 * 求两个颜色之间的渐变值
	 * @param {string} startColor 开始的颜色
	 * @param {string} endColor 结束的颜色
	 * @param {number} step 颜色等分的份额
	 * */
	colorGradient(startColor = 'rgb(0, 0, 0)', endColor = 'rgb(255, 255, 255)', step = 10) {
   
		const startRGB = this.hexToRgb(startColor, false) // 转换为rgb数组模式
		const startR = startRGB[0]
		const startG = startRGB[1]
		const startB = startRGB[2]

		const endRGB = this.hexToRgb(endColor, false)
		const endR = endRGB[0]
		const endG = endRGB[1]
		const endB = endRGB[2]

		const sR = (endR - startR) / step // 总差值
		const sG = (endG - startG) / step
		const sB = (endB - startB) / step
		const colorArr = []
		for (let i = 0; i < step; i++) {
   
			// 计算每一步的hex值
			let hex = this.rgbToHex(`rgb(${
     Math.round((sR * i + startR))},${
     Math.round((sG * i + startG))},${
     Math.round((sB
				* i + startB))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值