Home > Web Front-end > JS Tutorial > Dynamically control the position of the layer according to the position of the mouse_javascript skills

Dynamically control the position of the layer according to the position of the mouse_javascript skills

WBOY
Release: 2016-05-16 18:41:18
Original
1147 people have browsed it
Copy code The code is as follows:

<script> <br>var index=0; //mouse It will be displayed when you click it for the first time. Click the mouse again and the layer will no longer be displayed <br>/**<br>* Mouse click event <br>*bizData: passed parameters <br>*/ <br>function search(bizData) <br>{ <br>if(index==0) <br> { <br>if(bizData==null) //When the parameter is empty, the content of this layer is cleared and null is not displayed <br>{ <br>$("bizDiv").innerText = ""; <br>$("bizDiv").style.background='#99FFFF'; <br>document.onclick = mouseMove; <br>index ; <br>}else <br>{ <br>$("bizDiv"). innerText = bizData; <br>$("bizDiv").style.background='#99FFFF'; //Relative page color settings<br>document.onclick = mouseMove; //Click trigger event<br>index; <br>} <br>}else{ //Second mouse click<br>$("bizDiv").innerText = ""; <br>document.onclick = mouseMove; <br>$("bizDiv") .style.background='transparent'; //Set the background color of the layer to "transparent color" <br>index=0; <br>} <br>} <br>/* <br>*Mouse move event, Get the position of top and right of the layer <br>*/ <br>function mouseMove(ev) <br>{ <br>ev= ev || window.event; <br>var mousePos = mouseCoords(ev); <br>$("bizDiv").style.right = document.body.clientWidth-mousePos.x 15; <br>$("bizDiv").style.top = document.body.clientHeight-200; <br>$( "bizDiv").style.width='200'; <br>//$("bizDiv").style.hight='200'; <br>} <br>/* <br>* Get the position of the mouse <br>*/ <br>function mouseCoords(ev) <br>{ <br>if(ev.pageX || ev.pageY){ <br>return {x:ev.pageX, y:ev.pageY}; <br>} <br>return { <br>x:ev.clientX document.body.scrollLeft - document.body.clientLeft, <br>y:ev.clientY document.body.scrollTop - document.body.clientTop <br>}; <br>} <br></script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template