SetTimeout Application Example-move in to move out div display and hide

Source: Internet
Author: User

Effect: Move in Div1,div2 remain displayed, move out div1,div2 disappear.

The move-in Div2,div2 remains displayed, and the move-out div2,div2 disappears.

First, the HTML code

<id= ' div1 '></div><  ID = ' Div2 ' ></ Div >

Just two div modules in G, move in one, show another.

Second, CSS code

Color two div, easy to distinguish, in CSS, I set the float property, define the element in the left direction floating

1 #div1{2 Height:50px;3 background:Grey;4 width:50px;5 float: Left;Border:1px6}7 #div2{8 float: Left;Border:1px;9 Height:50px;Ten background:Blue; One width:50px; A Display:None; -      -}

Three JavaScript code

1<script>2Window.onload=function(){3     varODiv1 = document.getElementById (' Div1 ')); 4     varODiv2 = document.getElementById (' Div2 ')); 5     varTimer =NULL;6Odiv1.onmouseover=odiv2.onmouseover =function(){7 cleartimeout (timer); return value by settimeout, clear settimeout8Odiv2.style.display= ' Block ';9         Ten          One         }; AOdiv1.onmouseout = Odiv2.onmouseout =function(){ -Timer = SetTimeout (function() {//Assign a value here to the timer, because the settimeout itself returns a value. This value is a settimeout ID of the system record, which can then be canceled by this ID . -              theOdiv2.style.display= ' None '; //Set the DIV2 module to disappear after 1000 milliseconds  -},1000); -          -         } +      -      +      A     }; at  -  -  -</script>

Iv. Demonstration of Effect

SetTimeout Application Example-move in to move out div display and hide

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.