CSS:

*{padding:;margin:;}
ul,li{list-style: none;}
body{color: #666;background: #f5f5f5;}
a{text-decoration: none;color: #666;}
.cont{
width: 400px;
margin: 30px auto;
position: relative;
background: #fff;
box-shadow: 2px 2px 5px #e6e2e2;
}
.tit_1,.tit_2,.tit_3,.tit_4{/*分类标题样式*/
height: 44px;
line-height: 44px;
position: relative;
padding-left: 40px;
}
.tit_1:before{/*标题部分的小三角形*/
content: '';
position: absolute;
left: 15px;
top: 12px;
border:10px solid transparent;
border-left-color:#ccc;
}
.tit_2:before{/*标题部分的小三角形*/
content: '';
position: absolute;
left: 15px;
top: 12px;
border:10px solid transparent;
border-left-color:#fff;
} .tit_3:before{/*标题部分的小三角形*/
content: '';
position: absolute;
left: 15px;
top: 17px;
border:10px solid transparent;
border-top-color:#ccc;
}
.tit_4:before{/*标题部分的小三角形*/
content: '';
position: absolute;
left: 15px;
top: 17px;
border:10px solid transparent;
border-top-color:#fff;
}
.active{/*列表内容的样式*/
height: 28px;
line-height: 28px;
padding-left: 40px;
cursor: pointer;
}
#ul1{
padding: 20px 0;
} .hidden{/*隐藏列表内容*/
display: none;
}
.on{/*显示列表内容*/
display: block;
}

HTML:

<div class="cont">
<ul id="ul1">
<li>
<h3 class="tit_1">护肤用品</h3>
<ul class="hidden">
<li>面部卸妆</li>
<li>眼部护理</li>
<li>卸妆油</li>
<li>卸妆棉</li>
</ul>
</li>
<li>
<h3 class="tit_1">彩妆香水</h3>
<ul class="hidden">
<li>隔离霜</li>
<li>BB霜</li>
<li>粉底液</li>
<li>腮红</li>
<li>唇彩</li>
</ul>
</li>
<li>
<h3 class="tit_1">个人护理</h3>
<ul class="hidden">
<li>头发护理</li>
<li>洗发水</li>
<li>发膜</li>
<li>焗油</li>
<li>护发素</li>
</ul>
</li>
<li>
<h3 class="tit_1">香水香氛</h3>
<ul class="hidden">
<li>女士香水</li>
<li>淡香水</li>
<li浓香水</li>
<li>男士香水</li>
<li>古龙香水</li>
<li>运动香水</li>
</ul>
</li>
</ul>
</div>

JS:

<script type="text/javascript">
var oUl=document.getElementById('ul1');
var aUl=oUl.getElementsByTagName('ul');
var aH=oUl.getElementsByTagName('h3');
var aLi=null;
var len=aUl.length; for (var i = 0; i <len; i++) {
aLi=aUl[i].getElementsByTagName('li');
for (var j = 0; j < aLi.length; j++) {
aLi[j].className='active';
aLi[j].onmouseover=function(){
//鼠标经过当前li,文字颜色发生变化
this.style.color='#e4007e';/*alert(4);*/
}
aLi[j].onmouseout=function(){
//鼠标离开当前li,文字颜色恢复原样
this.style.color='#666';
}
};
}; for (var i = 0; i < aH.length; i++) {
aH[i].index=i;
//鼠标经过当前h3时,背景色、字体颜色改变
aH[i].onmouseover=function(){
this.style.backgroundColor='#e4007e';
this.style.color='#fff';
//判断当前列表li下的内容是否展开
if (aUl[this.index].className=='hidden') {
this.className='tit_2';//列表内容隐藏时,小三角形的样式tit_2
}
else{
this.className='tit_4';//列表内容展开时,小三角形的样式tit_4
};
}
aH[i].onmouseout=function(){
this.style.backgroundColor='#fff';
this.style.color='#666';
//判断当前列表li下的内容是否展开
if (aUl[this.index].className=='hidden') {
this.className='tit_1';//列表内容展开时,小三角形的样式tit_1
}
else{
this.className='tit_3';//列表内容展开时,小三角形的样式tit_3
};
} aH[i].onclick=function(){
//点击当前h3,如果列表下的内容隐藏,则将其显示出来,否则隐藏起来
if (aUl[this.index].className=='hidden') {
aUl[this.index].className='on';
this.className='tit_4';
}
else{
aUl[this.index].className='hidden';
this.className='tit_2';
};
}
/*alert(1);*/
};
</script>

JS产品分类列表练习的更多相关文章

  1. 《React后台管理系统实战 :四》产品分类管理页:添加产品分类、修改(更新)产品分类

    一.静态页面 目录结构 F:\Test\react-demo\admin-client\src\pages\admin\category add-cate-form.jsx index.jsx ind ...

  2. 企业架构研究总结(29)——TOGAF架构内容框架之概述及架构工作产品分类

    在TOGAF 9之前的版本中,TOGAF的重点主要集中在企业架构开发方法方面,用于指导其使用者如何在各自的组织中对企业架构进行创建和维护,而对于企业架构的具体内容并没有相关的论述,因而针对早期TOGA ...

  3. TOGAF架构内容框架之概述及架构工作产品分类

    TOGAF架构内容框架之概述及架构工作产品分类 在TOGAF 9之前的版本中,TOGAF的重点主要集中在企业架构开发方法方面,用于指导其使用者如何在各自的组织中对企业架构进行创建和维护,而对于企业架构 ...

  4. 微信小程序 仿‘得到app’分类列表页

    今天另起一篇,贴出完整的代码,大概思路是左侧大分类列表,点击后联动右侧二级分类,及下面文章列表,点击二级分类也联动下面文章列表. 代码如下: <view class="page&quo ...

  5. axios模块封装和分类列表实现

    这个作用 主要还是为了让代码更加的,清晰. 不要全部都放到  created(){}  这个方法下面.把这些代码全部抽离出去. 这里就只是去调用方法.1. src 目录下,新建文件夹---  rest ...

  6. 原生js移动端列表无缝间歇向上滚动

    在项目开发中尤其是在项目的活动页面的开发中,经常需要将用户的购买信息或中奖信息等以列表的形式展示在页面当中,并可以使其自动间歇向上滚动来达到在有限的区域内展示所有信息的目的.通常的做法是通过将列表父元 ...

  7. PHP多条件分类列表筛选功能开发实例

    PHP多条件分类列表筛选功能开发实例,前后台一起实现 后台对接可以拼接sql语句,PHP通过表单值隐藏值筛选,常用又实用! 表单筛选核心函数 function Filter(a, b) { var $ ...

  8. WordPress分类列表函数:wp_list_categories用法及参数详解举例

    http://www.511yj.com/wordpress-wp-categories.html 注意: 1. wp_list_categories() 和 list_cats() 以及 wp_li ...

  9. 分享JQuery动画插件Velocity.js的六种列表加载特效

    分享JQuery动画插件Velocity.js的六种列表加载特效.在这款实例中给中六种不同的列表加载效果.分别为从上飞入.从右侧飞入.从左侧飞入.和渐显.一起看下效果图: 在线预览   源码下载 实现 ...

随机推荐

  1. Atitit. 。Jna技术与 解决 java.lang.Error: Invalid memory access

    Atitit. .Jna技术与 解决 java.lang.Error: Invalid memory access 1. 原因与解决1 2. jNA (这个ms sun 的)1 3. Code1 4. ...

  2. 小马哥课堂-统计学-t分布(2)

    t分布,随着自由度的增加,而逐渐接近于正态分布 #!/usr/bin/env python3 #-*- coding:utf-8 -*- ############################### ...

  3. matplotlib之设置极坐标起点的位置

    #!/usr/bin/env python3 #-*- coding:utf-8 -*- ############################ #File Name: polar.py #Auth ...

  4. plist 与 JOSN的解析

  5. Linux_Command

    系统 # uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # ho ...

  6. JavaScript中的对象冒充

    JavaScript里没有继承关键字,想要继承一个类需要用到“对象冒充”. <!DOCTYPE html> <html xmlns="http://www.w3.org/1 ...

  7. C0304 备份最后一天所有修改的文件

    #! /bin/bash backupfile=backup-$(date +%m-%d-%Y) archive=${1:-$backupfile} # 上边内容, 参数替换 ${} echo $ar ...

  8. 【BZOJ】3432: [Usaco2014 Jan]Cross Country Skiing (bfs+二分)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3432 题目说要相互可达,但是只需要从某个点做bfs然后判断其它点是否可达即可. 原因太简单了.... ...

  9. 正确的关机方法: sync, shutdown, reboot, halt, poweroff, init

    正常情况下,要关机时需要注意底下几件事: 观察系统的使用状态: 如果要看目前有谁在在线,可以下达『who』这个命令,而如果要看网络的联机状态,可以下达 『 netstat -a 』这个命令, 而要看背 ...

  10. ubuntu16.04主题美化和软件推荐(转载)

    从这里转载!转载!转载! http://blog.csdn.net/terence1212/article/details/52270210