JS exercises-nested list (for loop), js nesting

Source: Internet
Author: User

JS exercises-nested list (for loop), js nesting

CSS:

* {Padding: 0; margin: 0;} ul, li {list-style: none ;}. cont {width: 600px; margin: 30px auto ;}. cont h3 {border-bottom: 2px solid # bbb; width: 100%; height: 38px ;}# ul1 {position: relative; width: 100% ;}# ul1> li {float: left; margin-top: 15px; margin-left: 15px; position: relative ;}. pro {width: 180px; height: 200px; overflow: hidden ;}. pro img {width: 180px; height: 150px; overflow: hidden ;}. pro p {text-align: center ;}. hidden {display: none ;}. active {width: 300px; height: 120px; padding: 10px; overflow: hidden; position: absolute; top:-80px; left: 20px; display: block; background: # eee; border: 1px solid # ccc; z-index: 1 ;}. active li {color: # e4007e; font-size: 14px; padding-left: 12px; height: 30px; line-height: 30px;}/* clear floating */. clearfix {zoom: 1 ;}. clearfix: after {content :'. '; height: 0; display: block; clear: both; visibility: hidden ;}

HTML:

<Div class = "cont"> 

JS:

<Script type = "text/javascript"> var oUl1 = document. getElementById ('ul1'); var aUl = oUl1.getElementsByTagName ('ul '); // ul array var aDiv = oUl1.getElementsByTagName ('div'); for (var I = 0; I <aDiv. length; I ++) {aDiv [I]. index = I; // index value // when the cursor passes through the current div, The div content under the current li displays aDiv [I]. onmouseover = function () {aUl [this. index]. className = 'active';} // when the mouse leaves the current div, The div content under the current li hides aDiv [I]. onmouseout = function () {aUl [this. index]. className = 'ddn' ;}}; </script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.