网页圆形透明滤镜

   <style>

        body {

            background: url(https://images.unsplash.com/photo-1519677100203-a0e668c92439)

            no-repeat center;

            background-size: cover;

            height: 100vh;

            cursor: none;

            padding: 0%;

            margin: 0%;

        }

        h1 {

            position: absolute;

            top: 50%;

            left: 50%;

            transform: translate(-50%, -50%);

            z-index: 1;

            font-family: "Roboto", Arial, sans-serif;

            font-size: calc(20px + 2vw);

            font-weight: 700;

            color: #fafafa;

            text-shadow: 2px 2px 2px #000;

            pointer-events: none;

            user-select: none;

            white-space: nowrap;

        }

        .spotlight {

            position: absolute;

            height: 100%;

            width: 100%;

            background-image: radial-gradient(circle,transparent 160px,rgba(0, 0, 0, 0.85) 200px);

            /* background-image: radial-gradient(circle,red , 160px,rgba(0, 0, 0, 0.85) 200px);

                1、transparent是透明色,颜色后面跟着px,颜色后面跟着px

                2、把transparent色改成red或者其他颜色就可以改变内圈的颜色

            */

        }

    </style>

</head>

<body>

    <h1>solo@reactiv3.com</h1>

    <div class="spotlight"></div>

    <script>

        window.addEventListener("DOMContentLoaded", () => {

            const spotlight = document.querySelector('.spotlight');

            let spotlightSize = 'transparent 160px, rgba(0, 0, 0, 0.85) 200px)';

            window.addEventListener('mousemove', e => updateSpotlight(e));

            window.addEventListener('mousedown', e => {

                spotlightSize = 'transparent 130px, rgba(0, 0, 0, 0.95) 150px)';

                updateSpotlight(e);

            });

            window.addEventListener('mouseup', e => {

                spotlightSize = 'transparent 160px, rgba(0, 0, 0, 0.85) 200px)';

                updateSpotlight(e);

            });

            function updateSpotlight(e) {

                spotlight.style.backgroundImage =

                `radial-gradient(circle at ${e.pageX / window.innerWidth * 100}%

                ${e.pageY / window.innerHeight * 100}%, ${spotlightSize}`;

            }

        });

    </script>

</body>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值