div 层怎么拖动 我想做成一个效果 就是进入页面的时候div层是 隐藏的 当 点击页面中一条记录的详细信息的时候 弹出来 居中 ,然后再标题的地方点击鼠标整个div层可以再 屏幕内拖动(注意是屏幕内哦,就是div 边框到屏幕边的时候就过不去了)。层可以很容易弹出来 但是怎么拖动 我真的不知道 求教啊 求教。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <!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=utf-8" /><title>无标题文档</title><script type="text/javascript">var colors=["yellow",'red','blue','black'];function Test(){ this.move=0; this.x=0; this.y=0; this.div=document.createElement("div"); this.div.style.width="200px"; this.div.style.height="200px"; this.div.style.left="100px"; this.div.style.top="100px"; this.div.style.position="absolute"; this.color=parseInt(Math.random()*colors.length); this.div.style.backgroundColor=colors[this.color]; this.div.onmousedown=this.can_move.bind(this); this.div.onmouseup=this.cannot_move.bind(this); this.div.onmousemove=this.show_move.bind(this); document.body.appendChild(this.div);}function add(){ new Test();}Test.prototype.can_move=function(e){ this.move=1; var a=e||window.event; var x0=a.clientX; var y0=a.clientY; this.x=parseInt(this.div.style.left)-x0; this.y=parseInt(this.div.style.top)-y0;}Test.prototype.cannot_move=function(){ this.move=0;}Test.prototype.show_move=function(e){ var a=e||window.evevt; var x0=a.clientX; var y0=a.clientY; if(this.move==1){ this.div.style.left=x0+this.x+"px"; this.div.style.top=y0+this.y+"px"; }}</script></head><body><input type="button" onclick="add()" value="add"></body></html>这样试试 这么复杂的功能,有jquery插件可以做的 javascript用ActiveXObject时IE弹出“安全警告”,如何去掉 我是菜鸟,帮我分析一下代码 关于对象和正则表达式匹配的 createpopup创建的窗口如何实现全屏 讨论提交 onsubmit onclick jsp中 javaScript取值问题,请大侠帮忙! 各位大虾,怎么实现图片切换?加链接,动态增加图片 如何让后退按钮失效? 请问如何是弹出的窗口没有关闭的按钮。非最大化状态下 多个object处理的问题 请大家帮我看看这段JS代码,很简单的IF语句,怎么完全无效呢 请教各位,利用 JS 导出(创建) word,速度太慢问题!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
var colors=["yellow",'red','blue','black'];
function Test(){
this.move=0;
this.x=0;
this.y=0;
this.div=document.createElement("div");
this.div.style.width="200px";
this.div.style.height="200px";
this.div.style.left="100px";
this.div.style.top="100px";
this.div.style.position="absolute";
this.color=parseInt(Math.random()*colors.length);
this.div.style.backgroundColor=colors[this.color];
this.div.onmousedown=this.can_move.bind(this);
this.div.onmouseup=this.cannot_move.bind(this);
this.div.onmousemove=this.show_move.bind(this);
document.body.appendChild(this.div);
}
function add(){
new Test();
}
Test.prototype.can_move=function(e){
this.move=1;
var a=e||window.event;
var x0=a.clientX;
var y0=a.clientY;
this.x=parseInt(this.div.style.left)-x0;
this.y=parseInt(this.div.style.top)-y0;
}
Test.prototype.cannot_move=function(){
this.move=0;
}
Test.prototype.show_move=function(e){
var a=e||window.evevt;
var x0=a.clientX;
var y0=a.clientY;
if(this.move==1){
this.div.style.left=x0+this.x+"px";
this.div.style.top=y0+this.y+"px";
}
}
</script>
</head><body>
<input type="button" onclick="add()" value="add">
</body>
</html>
这样试试