Practical CSS: DIV + CSS creates a layer that follows the mouse

Source: Internet
Author: User

[Document of the institute of fire station building school] Today I will write a practical CSS tutorial, "DIV + CSS build a layer that follows the mouse". In order to facilitate your learning, I will divide the code into two parts, 2. executable code.

Reference content is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> layer following the mouse-Fire Site Building Institute </title>
<Script type = "text/javascript">
Function show_mp ()
{
Var obj = document. getElementById ('mpdiv ');
Var L = T = 0;
Var divWidth = 220;
Var divHeight = 70;
Var padding = 15;
Var R = document. body. scrollLeft + document. body. clientWidth-divWidth;
Var B = document. body. scrollTop + document. body. clientHeight-divHeight;
Var x = document. body. scrollLeft + event. clientX;
Var y = document. body. scrollTop + event. clientY;

Obj. style. display = "none ";
If (x <L) {x = x + divWidth ;}
If (x> R) {x = x-divWidth-padding * 2 ;}
If (y <T) {y = T + divHeigh ;}
If (y> B) {y = B-padding * 2 ;}
Obj. style. left = x + padding;
Obj. style. top = y + padding;
Obj. style. display = "";
}
Function hidden_mp ()
{
Var obj = document. getElementById ('mpdiv ');
Obj. style. display = "none ";
}
</Script>
</Head>
<Body>
<A href = "#" onMouseOver = "show_mp ()" onMouseOut = "hidden_mp ()"> afasdfds </a>
<Div id = "mpDiv" style = 'width: 220px; overflow: hidden; position: absolute; z-index: 5; display: none; '>
<Table width = "220" border = "0" cellpadding = "0" cellspacing = "1" bgcolor = "# fc9c0a">
<Tr>
<Td height = "70" valign = "top" bgcolor = "# ffffff" style = 'padding: 5px; '> </td>
</Tr>
</Table>
</Div>
</Body>
</Html>

 

<Html> 

Run code Copy code Save code Add to favorites

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.