js+css实现换肤效果
作者:吃葡萄不吐葡萄皮嘻嘻 发布时间:2024-04-17 09:53:54
标签:js,css,换肤
本文实例为大家分享了js+css实现换肤效果的具体代码,供大家参考,具体内容如下
效果图如下:
需求:点击对应小圆点,下面内容颜色跟着改变
主要思路:
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>
来源:https://blog.csdn.net/qq_45695853/article/details/119350792


猜你喜欢
- 零、前言python代码中配置文件是必不可少的内容。常见的配置文件格式有很多中:ini、yaml、xml、properties、txt、py
- 1.python实现对doc文档的读取#读取docx中的文本代码示例import docx#获取文档对象file=docx.Document
- 这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享。1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完
- .xls格式 Office2003及以下版本 .xlsx格式Offi
- 一、MySQL Workbench简介MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,属于 Oracle 旗下产品。
- 接触编程的朋友都听过正则表达式,在python中叫re模块,属于文字处理服务里面的一个模块。re里面有一个方法叫match,接下来的文章我来
- 本文实例讲述了js实现黑色简易的滑动门网页tab选项卡效果。分享给大家供大家参考。具体如下:这是一款js实现的黑色风格网页滑动门菜单,虽然简
- 一、Can't connect to MySQL server on 'localhost'(10061
- 代码如下:var obj = document.getElementById("name"
- <?php //作者:遥远的期待 //QQ:15624575 //算法分析:1、必须是整数序列、2、如果整个序列不全是负数,最大子序列
- 一、ROC与AUC很多学习器是为了测试样本产生的一个实值或概率预测,然后将这个预测值与一个分类阈值(threshold)进行比较,若大于阈值
- 推荐系统中经常需要处理类似user_id, item_id, rating这样的数据,其实就是数学里面的稀疏矩阵,scipy中提供了spar
- 1.SQL Server2019安装包下载1.1进入官网SQL Server 20191.2下载安装包1点击Continue2.填写个人信息
- 本文为大家分享了mysql 8.0.15 winx64安装配置方法,供大家参考,具体内容如下1.去官网下载最新版本的适用于window下的6
- --创建链接服务器 exec sp_addlinkedserver &
- 1. 首先确认python的版本为2.3.4以上,如果不是需要升级python的版本 python -V
- 主键索引排序失效环境:MySQL8有一张用户信息表user_info,建表DDL如下:CREATE TABLE `user_info` (
- 作用有局限性,必须在指定的环境下,才能匹配成功,是受到很多因素的影响,所以有一定的适应性模板匹配是一种最原始、最基本的模式识别方法,研究某一
- 0X01函数说明:python range() 函数可创建一个整数列表,一般用在 for 循环中。0X02函数语法:range(start,
- 本文主要概括安装时提示有挂起的操作、收缩数据库、压缩数据库、转移数据库给新用户以已存在用户权限、检查备份集、修复数据库等操作技巧。1.挂起操