js實現(xiàn)一鍵換膚效果
更新時間:2022年07月01日 15:29:01 作者:Cheryl71
這篇文章主要為大家詳細介紹了js實現(xiàn)一鍵換膚效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)一鍵換膚效果的具體代碼,供大家參考,具體內(nèi)容如下
方法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>
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
JS組件中bootstrap multiselect兩大組件較量
這篇文章主要介紹了JS組件中bootstrap multiselect兩大組件,兩者之間的較量,優(yōu)缺點比較,感興趣的小伙伴們可以參考一下2016-01-01javascript與jquery動態(tài)創(chuàng)建html元素示例
這篇文章主要介紹了javascript與jquery動態(tài)創(chuàng)建html元素的方法,結(jié)合實例形式分析了javascript與jQuery動態(tài)創(chuàng)建頁面元素的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2016-07-07JS實現(xiàn)數(shù)字格式千分位相互轉(zhuǎn)換方法
下面小編就為大家?guī)硪黄狫S實現(xiàn)數(shù)字格式千分位相互轉(zhuǎn)換方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08TypeError: Cannot set properties of 
這篇文章主要介紹了TypeError: Cannot set properties of undefined (setting ‘xx‘)的問題,本文給大家分享完美解決方案,需要的朋友可以參考下2023-09-09JavaScript canvas實現(xiàn)圍繞旋轉(zhuǎn)動畫
這篇文章主要為大家詳細介紹了JavaScript canvas實現(xiàn)圍繞旋轉(zhuǎn)動畫,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11