Js simple drag layer effect

Source: Internet
Author: User
Tip: you can modify some code before running

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>Js simple drag</title><style>*{margin:0;padding:0;overflow:hidden}html,body{width:100%;height:100%;}#SeachWin {width:508px;height:324px;overflow:hidden;position:absolute;background-color:#cff;cursor:default;text-align:center;line-height:200px;}#SeachWin tt#SeachTitle{display:block;font-size:12px;height:24px;line-height:26px;padding-left:25px;color:#fff;background-color:#00f;}</style><script>var IsD=false;//当前是否可以拖动var marx;//按下左键时光标的X坐标与对话框的X坐标之差var mary;//按下左键时光标的Y坐标与对话框的Y坐标之差function MoveDown(event){//按下左键时获取光标的坐标与对话框的坐标之差if(IsD==false){var d=document.getElementById("SeachWin");marx=d.style.left;mary=d.style.top;marx=marx.replace('px','');mary=mary.replace('px','');marx=marx-(event.x ? event.x : event.pageX);mary=mary-(event.y ? event.y : event.pageY);}IsD=true;}function move1(event){//改变对话框的坐标实现移动(对话框的坐标=按下左键时获取光标的坐标与对话框的坐标之差+移动后的光标坐标)if(IsD==true){var d=document.getElementById("SeachWin");var x=eval((event.x ? event.x : event.pageX)+marx);var y=eval((event.y ? event.y : event.pageY)+mary);if(y<0)y=0;d.style.left=x +"px";d.style.top=y+"px";}}function DocOut(){//鼠标移出body外时,搜索框不能拖动IsD=false;}//document.onmousemove=move1;//document.onmouseout=DocOut;</script></head><body onmousemove="move1(event)" onmouseout="IsD=false;//鼠标移出body外时,搜索框不能拖动"> <!--<body>--><div id="SeachWin"> <tt id="SeachTitle" onmousedown="MoveDown(event);" onmouseup="IsD=false;//鼠标移出后,搜索框不能拖动" onselectstart="return false" oncontextmenu="window.event.returnValue=false">Click the left button in this area to drag it.</tt>This is a simulated dialog box.</div></body></html>
Tip: you can modify some code before running

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.