• jquery+css 实现即时变化颜色主题(通过input输入颜色值进行改变)


    实现效果需要自行导入jquery.js

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <script type="text/JavaScript" src="js/jquery.js"></script>
    </head>
    <style>
        div section{ 
            width: 30px; 
            height: 30px; 
            margin: 10px; 
            display: inline-block; 
        }
        div section{ 
            background-color: black; 
            border-radius: 50%;
        }
        div section:hover{ 
            cursor:pointer;
        }
        div input,
        div button{
            position: absolute;
            margin-top: 10px;
            height: 30px; 
            width: 230px;
        }
        div button{
            width: 50px;
            margin-left: 240px;
            cursor:pointer;
        }
    </style>
    <body>
        <div>
            <section onclick="instantClick()" id="insC"></section>
            <input type="text" id="insInput" oninput="instantChange()" onpropertychange="instantChange()" placeholder="请您输入十六进制颜色码,如#123123。" maxlength="7">
            <button onclick="instantClick()">确认</button>
        </div>
        
        <center>
            <h2 style="display:inline-block;">颜色主题jquery变换</h2>
            <form action="" id="simpleCalc">
                <span>input:</span><input type="text" required><br><br>
                <button id="calc">开始计算</button>
            </form>
            <span id="result"></span>
        </center>
    
        <script>
            //即时换色
            // 设置需要换色的元素及其样式(与上一篇相同)
            function change(colo){
                $("#calc").css("background-color", colo);
                $("h2, small, span").css("color", colo);
                $("input").css("color", colo);
                $("input[type=text]").focus(function(){$(this).css("outline", "none")});
                $("input[type=text]").focus(function(){$(this).css("border", "2px solid " + colo)});
                $("input[type=text]").blur(function(){$(this).css("border", "1px solid gray")});
            }
            // 设置input输入的颜色值
            var colorC;
            function instantChange(){
                colorC = $("#insInput").val();
                // 改变section的背景色
                $("#insC").css("background-color", colorC);
            } 
            // 调用页面换色方法
            function instantClick(){
                change(colorC);
            }
            
        </script>
    </body>
    </html>

    如有错误,请您指正!

  • 相关阅读:
    Visual Studio 连接不上NuGet 官方程序包源的解决办法
    Microsoft Toolkit 2.5下载 – 一键激活Windows 8.1/2012 R2/Office 2013
    Intel® Ethernet Connection I217-V 网卡驱动(win10 ,2012)
    flashfxp3.41中文版注册码:(适合最新版本)
    Fiddler对安卓应用手机抓包图文教程
    网址检查器1.0
    Win10打不开chm文件的解决办法
    Android HTTP通讯
    对Android开发者有益的40条优化建议
    IIS下PHP的三种配置方式比较
  • 原文地址:https://www.cnblogs.com/ksl666/p/6626905.html
Copyright © 2020-2023  润新知