JavaScript

点击图片变换图片颜色

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>点击图片变换颜色</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        img {
            width: 800px;
            height: 800px;
            transition: filter 0.5s;
        }
    </style>
    <script>
        $(document).ready(function() {
            let isColored = false;
            $('#changeColor').click(function() {
                if (isColored) {
                    $(this).css('filter', 'none');
                } else {
                    $(this).css('filter', 'grayscale(100%)');
                }
                isColored = !isColored;
            });
        });
    </script>
</head>
<body>
    <img id="changeColor" src="https://nimg.ws.126.net/?url=http%3A%2F%2Fdingyue.ws.126.net%2F2024%2F0219%2Fc43c3d3dj00s930uu002sd000xs00zop.jpg&thumbnail=660x2147483647&quality=80&type=jpg" alt="图片">
</body>
</html>

点击前

点击后

点击背景颜色渐变方向转变

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>背景颜色渐变方向变换</title>
    <style>
        body {
            height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background 0.5s;
        }
    </style>
</head>
<body>
    <script>
        let direction = 'to right';

        document.body.addEventListener('click', function() {
            if (direction === 'to right') {
                direction = 'to left';
            } else if (direction === 'to left') {
                direction = 'to top';
            } else if (direction === 'to top') {
                direction = 'to bottom';
            } else {
                direction = 'to right';
            }

            document.body.style.background = `linear-gradient(${direction}, #ff9a9e, #fad0c4)`;
        });
        document.body.style.background = `linear-gradient(${direction}, #ff9a9e, #fad0c4)`;
    </script>
</body>
</html>

点击前

点击后

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值