Sharing: simple code and compatible with the drag layer of multiple browsers

Source: Internet
Author: User
  1   <!  Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"  >  
2   < Html Xmlns = "Http://www.w3.org/1999/xhtml" >
3   < Head >
4   < Title > CodeVery simple and compatible with the drag layer of multiple browsers </ Title >
5 </ Head >
6 < Body >
7 < Div ID = "F" Style = "Position: absolute; width: 500px; Height: 350px; Background-color: # CCC; top: 150px; left: 200px; Z-index: 101; Border: solid 1px blue ;" >
8 < Div ID = "Title" Style = "Background-color: Blue; cursor: move; Height: 20px; color: # FFF; font-size: 13px; padding-top: 5px; padding-left: 10px ;" > Here is the layer title websjy.com </ Div >
9 </ Div >
10
11 < Script Type = "Text/JavaScript" >
12 VaR Posx;
13 VaR Posy;
14 Fdiv = Document. getelementbyid ( " F " );
15 Document. getelementbyid ( " Title " ). Onmousedown = Function (E)
16 {
17 If ( ! E) E = Window. event;
18 Posx = E. clientx - Parseint (fdiv. style. Left );
19 Posy = E. clienty - Parseint (fdiv. style. Top );
20 Document. onmousemove = Mousemove;
21 }
22 Document. onmouseup = Function ()
23 {
24 Document. onmousemove = Null ;
25 }
26 Function Mousemove (EV)
27 {
28 If (EV = Null ) EV = Window. event;
29 Fdiv. style. Left = (EV. clientx - Posx) + " Px " ;
30 Fdiv. style. Top = Ev. clienty - Posy + " Px " ;
31 }
32 </ Script >
33 </ Body >
34 </ Html >

 

View demo results

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.