js實現(xiàn)一鍵換膚效果
更新時間:2022年07月01日 15:29:01 作者:Cheryl71
這篇文章主要為大家詳細介紹了js實現(xiàn)一鍵換膚效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)一鍵換膚效果的具體代碼,供大家參考,具體內容如下
方法1

<!DOCTYPE html>
<html lang="en">
<head>
? <meta charset="UTF-8">
? <meta http-equiv="X-UA-Compatible" content="IE=edge">
? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? <title>一鍵換膚</title>
? <style>
? ? :root {
? ? ? --color: white;
? ? }
? ? .card {
? ? ? width: 120px;
? ? ? height: 200px;
? ? }
? ? .controller {
? ? ? display: flex;
? ? ? justify-content: space-between;
? ? ? align-items: center;
? ? ? padding: 10px;
? ? }
? ? .btn {
? ? ? border: none;
? ? ? height: 30px;
? ? ? width: 100px;
? ? ? color: #eeeeee;
? ? ? background: linear-gradient(45deg, #ce7777, lightblue, #c19fc1, transparent);
? ? ? border-radius: 999px;
? ? ? box-shadow: 0 0 2px 2px #eeeeee;
? ? ? cursor: pointer;
? ? }
? ? .card {
? ? ? border-radius: 5px;
? ? ? box-shadow: 0 0 2px 2px rgb(126, 124, 124);
? ? }
? ? .card:nth-child(1) {
? ? ? background: black;
? ? }
? ? .card:nth-child(3) {
? ? ? background: white;
? ? }
? ? html, body {
? ? ? background: var(--color);
? ? ? opacity: 0.9;
? ? }
? ? body {
? ? ? height: 100vh;
? ? }
? ? *{
? ? ? margin: 0;
? ? ? padding: 0;
? ? }
? </style>
</head>
<body>
? <div class="controller">
? ? <div class="card"></div>
? ? <div><button class="btn" onclick="changeSkin()">一鍵換膚</button></div>
? ? <div class="card"></div>
? </div>
</body>
</html>方法2
<!DOCTYPE html>
<html lang="en">
<head>
? <meta charset="UTF-8">
? <meta http-equiv="X-UA-Compatible" content="IE=edge">
? <meta name="viewport" content="width=device-width, initial-scale=1.0">
? <title>change skin</title>
? <style id="theme">
? ? :root {
? ? ? --bgColor: #f00;
? ? }
? ? .skin {
? ? ? background: var(--bgColor);
? ? ? width: 200px;
? ? ? height: 200px;
? ? }
? </style>
</head>
<body>
? <div class="skin"></div>
? <button type="button" onclick="changeSkin('black')">change theme</button>
? <script>
? ? changeSkin = (theme) => {
? ? ? console.log("function starts");
? ? ? document.getElementById("theme").innerHTML = `
? ? ? ? :root{--bgColor:${theme};}
? ? ? ? .skin {
? ? ? ? ? background: var(--bgColor);
? ? ? ? ? width: 200px;
? ? ? ? ? height: 200px;
? ? ? ? }
? ? ? `
? ? }
? ?
? </script>
</body>
</html>以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JavaScript面試技巧之數(shù)組的一些不low操作
這篇文章主要給大家介紹了關于JavaScript面試技巧之數(shù)組的一些不low操作的相關資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用js具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-03-03
JS腳本實現(xiàn)動態(tài)給標簽控件添加事件的方法
這篇文章主要介紹了JS腳本實現(xiàn)動態(tài)給標簽控件添加事件的方法,結合實例形式分析了javascript添加事件監(jiān)聽的相關實現(xiàn)技巧,需要的朋友可以參考下2016-06-06

