[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