jQuery-图片变换和JS变化渐变色

jQuery-图片变换

源代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片转换</title>
    <script src="./JQuery.js"></script>
</head>
<body>
<div style="background-color: red;" id="div1">
    <img id="png" src="./坚强.png" alt=""/>
</div>
</body>
</html>
<script>
        $("#png").click(function () {
            if ($(this).attr("src")=="./可惜.png"){
                $("#div1").attr("style","background-color: red")
                $(this).attr("src","./坚强.png")
            }else {
                $(this).attr("src","./可惜.png")
                $("#div1").attr("style","background-color: yellow")
            }
        });
</script>

运行结果

注:Jquery无法使用需要添加链接,例:<script src="./JQuery.js"></script>

JS变化渐变色

源代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>背景渐变转换</title>
    <style>
        div{
            height: 700px;
        }
    </style>
</head>
<body>
    <div style=" background-image: linear-gradient(to right,red,yellow); " class="divclass" onclick="change()"></div>
</body>
</html>
<script>
    var div1 =document.getElementsByClassName("divclass")[0];
    function change(){
        if(div1.className =="divclass"){
            div1.className ="divclass1";
            div1.setAttribute("style","background-image: linear-gradient(to top,red,yellow);");
        }else if(div1.className =="divclass1"){
            div1.className ="divclass2";
            div1.setAttribute("style","background-image: linear-gradient(to left,red,yellow);");
        }else if(div1.className =="divclass2"){
            div1.className ="divclass3";
            div1.setAttribute("style","background-image: linear-gradient(to bottom,red,yellow);");
        }else{
            div1.className ="divclass";
            div1.setAttribute("style","background-image: linear-gradient(to right,red,yellow);");
        }
    }
</script>

运行结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值