RGB模型(html+css)

这是老师布置的一个作业,本来是要用matlab实现rgb的模型的,奈何电脑中全是学习资源,matlab又太过庞大,所以早就卸载了,老师说可以用其他的方法去实现rgb模型,我想了想,没想出来......

先看看实现的效果:

实现代码:


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input id="btn1" value='#ff0000' onchange="give1()" type="color">
    <input id="btn2" value='#00ff00' onchange="give2()" type="color">
    <input id="btn3" value='#0000ff' onchange="give3()" type="color">

    <div class="color1" style="position: relative;left: 300px; width: 200px;height: 200px;border-radius: 50%;background-color:rgb(255, 0, 0)">
        <div class="color2" style="position: absolute;top: 50%;left: -25%; width: 200px;height: 200px;border-radius: 50%; background-color:rgb(0, 255, 0);mix-blend-mode: screen;">
            <div class="color3" style="position: absolute;top: 0%;left: 50%; width: 200px;height: 200px;border-radius: 50%; background-color:rgb(0, 0, 255);mix-blend-mode: screen;"></div>
        </div>
    </div>
    <script>
        let btn1=document.getElementById('btn1');
        let btn2=document.getElementById('btn2');
        let btn3=document.getElementById('btn3');
        let color1=document.getElementsByClassName('color1')[0];
        let color2=document.getElementsByClassName('color2')[0];
        let color3=document.getElementsByClassName('color3')[0];
        let give1=()=>{
            console.log(btn1.value);
            color1.style.backgroundColor=btn1.value;
        }
        let give2=()=>{
            // console.log(btn1.value);
            color2.style.backgroundColor=btn2.value;
        }
        let give3=()=>{
            // console.log(btn1.value);
            color3.style.backgroundColor=btn3.value;
        }
    </script>
</body>

</html>

关于mix-blend-mode的使用,请移步https://www.jianshu.com/p/7a6fe5d29252

兼容性:兼容 谷歌  火狐  不兼容ie 和 Microsoft Eage

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值