Dynamic control layer position based on the mouse position

Source: Internet
Author: User

Copy codeThe Code is as follows:
<Script>
Var index = 0; // It is displayed when you click the mouse for the first time. If you click the mouse again, the layer is not displayed.
/**
* Mouse click event
* BizData: passed Parameter
*/
Function search (bizData)
{
If (index = 0)
{
If (bizData = null) // when the parameter is null, the content of this layer is cleared so that null is not displayed.
{
$ ("BizDiv"). innerText = "";
$ ("BizDiv"). style. background = '# 99ffff ';
Document. onclick = mouseMove;
Index ++;
} Else
{
$ ("BizDiv"). innerText = bizData;
$ ("BizDiv"). style. background = '# 99ffff'; // set the color of the relative page
Document. onclick = mouseMove; // click to trigger the event.
Index ++;
}
} Else {// second mouse click
$ ("BizDiv"). innerText = "";
Document. onclick = mouseMove;
$ ("BizDiv"). style. background = 'transparent'; // set the background color of the layer to "transparent"
Index = 0;
}
}
/*
* Move the cursor over the event to obtain the top and right positions of the layer.
*/
Function mouseMove (ev)
{
Ev = ev | window. event;
Var mousePos = mouseCoords (ev );
$ ("BizDiv"). style. right = document. body. clientWidth-mousePos.x + 15;
$ ("BizDiv"). style. top = document. body. clientHeight-200;
$ ("BizDiv"). style. width = '000000 ';
// $ ("BizDiv"). style. hight = '2013 ';
}
/*
* Get the cursor position
*/
Function mouseCoords (ev)
{
If (ev. pageX | ev. pageY ){
Return {x: ev. pageX, y: ev. pageY };
}
Return {
X: ev. clientX + document. body. scrollLeft-document. body. clientLeft,
Y: ev. clientY + document. body. scrollTop-document. body. clientTop
};
}
</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.