最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js+css實現(xiàn)換膚效果

 更新時間:2022年07月03日 05:46:57   作者:吃葡萄不吐葡萄皮嘻嘻  
這篇文章主要為大家詳細介紹了js+css實現(xiàn)換膚效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了js+css實現(xiàn)換膚效果的具體代碼,供大家參考,具體內(nèi)容如下

效果圖如下:

需求:點擊對應小圓點,下面內(nèi)容顏色跟著改變

主要思路:

1.在css中把對應的樣式先寫好;
2.獲取小圓點給它綁定點擊事件;
3.獲取當前點擊元素的類名;
4.將該類名設置給body;

js主要考察的是獲取屬性值和設置屬性值;

<style>
? ? ? ? *{
? ? ? ? ? ? margin:0;
? ? ? ? ? ? padding:0;
? ? ? ? ? ? list-style: none;
? ? ? ? }
? ? ? ? .dot{
? ? ? ? ? ??
? ? ? ? ? ? margin:100px auto;
? ? ? ? ? ? display: flex;
? ? ? ? ? ? justify-content: center;

? ? ? ? }
? ? ? ? .dot li{
? ? ? ? ? ? width: 30px;
? ? ? ? ? ? height: 30px;
? ? ? ? ? ? border-radius: 50%;
? ? ? ? ? ?cursor: pointer;
? ? ? ? }
? ? ? ? .dot li:first-child{
? ? ? ? ? ? background:pink;
? ? ? ? }
? ? ? ? .dot li:nth-child(2){
? ? ? ? ? ? background:green;
? ? ? ? }
? ? ? ? .dot li:nth-child(3){
? ? ? ? ? ? background:gold;
? ? ? ? }
? ? ? ? .dot li:last-child{
? ? ? ? ? ? background:skyblue;
? ? ? ? }
? ? ? ? .dot li:not(:last-child){
? ? ? ? ? ? margin-right: 10px;
? ? ? ? }
? ? ? ? .content{
? ? ? ? ? ? margin:100px auto;
? ? ? ? ? ? width: 300px;
? ? ? ? }
? ? ? ? .pink .content .banner{
? ? ? ? ? ? height: 160px;
? ? ? ? ? ? width: 100%;
? ? ? ? ? ? background:pink;
? ? ? ? }
? ? ? ? .pink .content li{
? ? ? ? ? ? color:pink;
? ? ? ? ? ? margin-bottom: 10px;
? ? ? ? ? ? border-bottom: 1px dashed pink;
? ? ? ? ? ? line-height: 40px;
? ? ? ? }

? ? ? ? .green .content .banner{
? ? ? ? ? ? height: 160px;
? ? ? ? ? ? width: 100%;
? ? ? ? ? ? background:green;
? ? ? ? }
? ? ? ? .green .content li{
? ? ? ? ? ? color:green;
? ? ? ? ? ? margin-bottom: 10px;
? ? ? ? ? ? border-bottom: 1px dashed green;
? ? ? ? ? ? line-height: 40px;
? ? ? ? }

? ? ? ? .gold .content .banner{
? ? ? ? ? ? height: 160px;
? ? ? ? ? ? width: 100%;
? ? ? ? ? ? background:gold;
? ? ? ? }
? ? ? ? .gold .content li{
? ? ? ? ? ? color:gold;
? ? ? ? ? ? margin-bottom: 10px;
? ? ? ? ? ? border-bottom: 1px dashed gold;
? ? ? ? ? ? line-height: 40px;
? ? ? ? }

? ? ? ? .skyblue .content .banner{
? ? ? ? ? ? height: 160px;
? ? ? ? ? ? width: 100%;
? ? ? ? ? ? background:skyblue;
? ? ? ? }
? ? ? ? .skyblue .content li{
? ? ? ? ? ? color:pink;
? ? ? ? ? ? margin-bottom: 10px;
? ? ? ? ? ? border-bottom: 1px dashed skyblue;
? ? ? ? ? ? line-height: 40px;
? ? ? ? }
</style>
<body class="pink">

? ? <ul class="dot">
? ? ? ? <li class="pink"></li>
? ? ? ? <li class="green"></li>
? ? ? ? <li class="gold"></li>
? ? ? ? <li class="skyblue"></li>
? ? </ul>

? ? <div class="content">
? ? ? ? <div class="banner"></div>
? ? ? ? <ul>
? ? ? ? ? ? <li>奶茶</li>
? ? ? ? ? ? <li>火鍋</li>
? ? ? ? ? ? <li>串串</li>
? ? ? ? ? ? <li>烤肉</li>
? ? ? ? </ul>
? ? </div>

? ? <script>
? ? ? ? window.onload = function(){
? ? ? ? ? ? let lis = document.querySelectorAll('.dot li');
? ? ? ? ? ? let body = document.querySelector('body');
? ? ? ? ? ? for(let i=0;i<lis.length;i++){
? ? ? ? ? ? ? ? lis[i].addEventListener('click',function(){
? ? ? ? ? ? ? ? ? ? // 獲取屬性值:元素名.屬性名 ?設置屬性值:元素名.屬性名 = 屬性值 ; ?移除屬性:元素名.屬性名 = "";(此種方法不能獲取,設置,移除自定義屬性)
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? ? ? //獲取屬性值 :元素名.getAttribute('屬性名') ?;設置屬性值:元素名.setAttribute('屬性名','屬性值') ;移除屬性:元素名.removeAttribute('屬性名') (此種方法能獲取,設置,移除自定義屬性,可對任何屬性有效)
? ? ? ? ? ? ? ? ? ? let color = this.getAttribute('class')
? ? ? ? ? ? ? ? ? ? body.setAttribute('class',color)
? ? ? ? ? ? ? ? })
? ? ? ? ? ? }
? ? ? ? }
? ? </script>
</body>

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 基于js實現(xiàn)數(shù)組相鄰元素上移下移

    基于js實現(xiàn)數(shù)組相鄰元素上移下移

    這篇文章主要介紹了基于js實現(xiàn)數(shù)組相鄰元素上移下移,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-05-05
  • javascript中的some方法使用解讀

    javascript中的some方法使用解讀

    這篇文章主要介紹了javascript中的some方法使用解讀,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-01-01
  • 基于javascript實現(xiàn)按圓形排列DIV元素(三)

    基于javascript實現(xiàn)按圓形排列DIV元素(三)

    本篇文章主要介紹基于javascript實現(xiàn)按圓形排列DIV元素的方法,此文著重于介紹怎樣實現(xiàn)圖片按橢圓形轉(zhuǎn)動,需要的朋友來看下吧
    2016-12-12
  • JS使用正則表達式實現(xiàn)常用的表單驗證功能分析

    JS使用正則表達式實現(xiàn)常用的表單驗證功能分析

    這篇文章主要介紹了JS使用正則表達式實現(xiàn)常用的表單驗證功能,結(jié)合實例形式分析了JS基于正則表達式的表單驗證功能原理、實現(xiàn)技巧與操作注意事項,需要的朋友可以參考下
    2020-04-04
  • 讓Firefox支持event對象實現(xiàn)代碼

    讓Firefox支持event對象實現(xiàn)代碼

    FireFox并沒有 window.event ,所以在FireFox下編寫事件處理函數(shù)是很麻煩的事。如果要得到 event 對象,就必須要聲明時間處理函數(shù)的第一個參數(shù)為event
    2009-11-11
  • JS函數(shù)重載的解決方案

    JS函數(shù)重載的解決方案

    在面向?qū)ο蟮木幊讨?,很多語言都支持函數(shù)重載,能根據(jù)函數(shù)傳遞的不同個數(shù)、類型的參數(shù)來做不同的操作,JS對它卻不支持,需要我們額外做些小動作。
    2014-05-05
  • JavaScript localStorage使用教程詳解

    JavaScript localStorage使用教程詳解

    JavaScriptlocalStorage基本上是瀏覽器Window對象中的存儲,您可以在中存儲任何內(nèi)容localStorage,localStorage及其相關(guān)的sessionStorage是 Web Storage API的一部分,我們將在本文詳細了解這些,需要的朋友可以參考下
    2023-06-06
  • ES6入門教程之Array.from()方法

    ES6入門教程之Array.from()方法

    這篇文章主要給大家介紹了關(guān)于ES6入門教程之Array.from()方法的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用ES6具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-03-03
  • 用js傳遞value默認值的示例代碼

    用js傳遞value默認值的示例代碼

    這篇文章主要介紹了用js傳遞value默認值的簡單實現(xiàn),很簡單但比較實用,需要的朋友可以參考下
    2014-09-09
  • 原生JS實現(xiàn)獲取及修改CSS樣式的方法

    原生JS實現(xiàn)獲取及修改CSS樣式的方法

    這篇文章主要介紹了原生JS實現(xiàn)獲取及修改CSS樣式的方法,結(jié)合實例形式簡單分析了JavaScript針對頁面元素屬性動態(tài)操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下
    2018-09-09

最新評論

犍为县| 静宁县| 辉南县| 晋江市| 清水河县| 巴林左旗| 霍林郭勒市| 凤凰县| 防城港市| 永康市| 庆安县| 伊吾县| 乳源| 峨山| 嘉祥县| 林西县| 孝昌县| 宁海县| 仁布县| 黄梅县| 平顶山市| 岗巴县| 吉林市| 安阳县| 黄大仙区| 将乐县| 内江市| 南岸区| 平果县| 蓝山县| 烟台市| 扶绥县| 吴忠市| 桑日县| 开远市| 长乐市| 阿拉善盟| 陆良县| 黄浦区| 紫金县| 武宁县|