HTML5技术

JS产品分类列表练习 - 洛水三千

字号+ 作者:H5之家 来源:博客园 2016-03-17 12:01 我要评论( )

CSS: * { padding : 0 ; margin : 0 ;} 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 : #f

CSS:

*{padding: 0;margin: 0;} 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:

护肤用品面部卸妆眼部护理卸妆油卸妆棉彩妆香水隔离霜BB霜粉底液腮红唇彩个人护理头发护理洗发水发膜焗油护发素香水香氛女士香水淡香水男士香水古龙香水运动香水

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(){ .style.color='#e4007e'; } aLi[j].onmouseout=function(){ .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'; (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'; (aUl[this.index].className=='hidden') { this.className='tit_1';//列表内容展开时,小三角形的样式tit_1 } else{ this.className='tit_3';//列表内容展开时,小三角形的样式tit_3 }; } aH[i].onclick=function(){ (aUl[this.index].className=='hidden') { aUl[this.index].className='on'; this.className='tit_4'; } else{ aUl[this.index].className='hidden'; this.className='tit_2'; }; } }; </script>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 【Vue 入门】使用 Vue2 开发一个展示项目列表的应用 - zhangjk

    【Vue 入门】使用 Vue2 开发一个展示项目列表的应用 - zhangjk

    2017-04-30 16:00

  • [微信产品经理推荐] 有车一族福音,这个小程序能够帮到你很多忙,功能很逆天! - 腾讯攻城师lee

    [微信产品经理推荐] 有车一族福音,这个小程序能够帮到你很多忙,功

    2017-04-13 08:03

  • 对产品经理的思考 - AnAnZ2

    对产品经理的思考 - AnAnZ2

    2017-04-12 13:00

  • 列表总结Canvas和SVG的区别 - 妙音天女

    列表总结Canvas和SVG的区别 - 妙音天女

    2017-03-17 10:00

网友点评