<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<script type="text/javascript">
function btn1_onclick()
{
var tt =$get("txt1").value;
SimpleWebService.Sayhello(tt,qq);
}
function qq(result)
{
var tmp1;
var tmp2;
var tmp3;
$get("zw").innerHTML=result;
$get("all").style.visibility = "visible";
$get("all").style.height=document.body.clientHeight;
$get("all").style.width=document.body.clientWidth;
$get("all").style.backgroundColor= "black";
tmp1=$get("all").style.height;
var tmpp1=new Array();
tmpp1 =tmp1.split("p");
tmp1=tmpp1[0];
alert(tmp1);
tmp2=$get("result").style.height;
var tmpp2=new Array();
tmpp2 =tmp2.split("p");
tmp2=tmpp2[0];
alert(tmp2);
tmp3= (tmp1 - tmp2)/2;
alert(tmp3);
// $get("result").style.marginTop = ($get("all").style.height-$get("result").style.height)/2;
// $get("result").style.marginleft=($get("all").style.width-$get("result").style.width)/2;
$get("result").style.marginTop =tmp3+"px";
// $get("result").style.marginTop = $get("result").style.height;
$get("result").style.visibility = "visible";
}
// function no()
// {
// $get("all").style.visibility="hidden";
// }
var move=false;
function StartDrag(obj)
{
if(event.button==1&&event.srcElement.tagName.toUpperCase()=="DIV")
{
obj.setCapture();
move=true;
}
} function Drag(obj)
{
if(move)
{
var oldwin=obj.parentNode;
oldwin.style.left=event.clientX-100;
oldwin.style.top=event.clientY-10;
} } function StopDrag(obj)
{
obj.releaseCapture();
move=false;
} </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="SimpleWebService.asmx" />
</Services>
</asp:ScriptManager>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="button" onclick="return btn1_onclick()" />
<div id="all" style="visibility:hidden; z-index:10;filter:alpha(opacity=40); float:left; left: 0px; position: absolute; top: 0px; text-align:center; ">
<div id="result" style="z-index:13;background-color:White;visibility:hidden; width:200px; height:100px">
<div id="title" style=" width:100%; height:20px; background-color:red; z-index:13;cursor: move" onmousedown="StartDrag(this)" onmouseup="StopDrag(this)" onmousemove="Drag(this)">测试移动aaaaaaaaa</div>
<div id="zw" style=" width:100%; height:100px; background-color:White; z-index:13" ></div>
</div>
</div>
</form>
</body>
</html>
我测试了,移动层的几个事件是运行了的,但是层就是没有移动
<script type="text/javascript">
function btn1_onclick()
{
var tt =$get("txt1").value;
SimpleWebService.Sayhello(tt,qq);
}
function qq(result)
{
var tmp1;
var tmp2;
var tmp3;
$get("zw").innerHTML=result;
$get("all").style.visibility = "visible";
$get("all").style.height=document.body.clientHeight;
$get("all").style.width=document.body.clientWidth;
$get("all").style.backgroundColor= "black";
tmp1=$get("all").style.height;
var tmpp1=new Array();
tmpp1 =tmp1.split("p");
tmp1=tmpp1[0];
alert(tmp1);
tmp2=$get("result").style.height;
var tmpp2=new Array();
tmpp2 =tmp2.split("p");
tmp2=tmpp2[0];
alert(tmp2);
tmp3= (tmp1 - tmp2)/2;
alert(tmp3);
// $get("result").style.marginTop = ($get("all").style.height-$get("result").style.height)/2;
// $get("result").style.marginleft=($get("all").style.width-$get("result").style.width)/2;
$get("result").style.marginTop =tmp3+"px";
// $get("result").style.marginTop = $get("result").style.height;
$get("result").style.visibility = "visible";
}
// function no()
// {
// $get("all").style.visibility="hidden";
// }
var move=false;
function StartDrag(obj)
{
if(event.button==1&&event.srcElement.tagName.toUpperCase()=="DIV")
{
obj.setCapture();
move=true;
}
} function Drag(obj)
{
if(move)
{
var oldwin=obj.parentNode;
oldwin.style.left=event.clientX-100;
oldwin.style.top=event.clientY-10;
} } function StopDrag(obj)
{
obj.releaseCapture();
move=false;
} </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Services>
<asp:ServiceReference Path="SimpleWebService.asmx" />
</Services>
</asp:ScriptManager>
<input id="txt1" type="text" />
<input id="btn1" type="button" value="button" onclick="return btn1_onclick()" />
<div id="all" style="visibility:hidden; z-index:10;filter:alpha(opacity=40); float:left; left: 0px; position: absolute; top: 0px; text-align:center; ">
<div id="result" style="z-index:13;background-color:White;visibility:hidden; width:200px; height:100px">
<div id="title" style=" width:100%; height:20px; background-color:red; z-index:13;cursor: move" onmousedown="StartDrag(this)" onmouseup="StopDrag(this)" onmousemove="Drag(this)">测试移动aaaaaaaaa</div>
<div id="zw" style=" width:100%; height:100px; background-color:White; z-index:13" ></div>
</div>
</div>
</form>
</body>
</html>
我测试了,移动层的几个事件是运行了的,但是层就是没有移动
jQuery可以简单实现拖动。
{
var tmp1;
var tmp2;
var tmp3;
$get("zw").innerHTML=result;
$get("all").style.visibility = "visible";
$get("all").style.height=document.body.clientHeight;
$get("all").style.width=document.body.clientWidth;
$get("all").style.backgroundColor= "black";
$get("result").style.left = document.body.scrollLeft+((document.body.clientWidth-200)/2)+'px';
$get("result").style.top = document.body.scrollTop+((document.body.clientHeight-100)/2)+'px';
$get("result").style.visibility = "visible";
}