我想做成一个效果 就是进入页面的时候div层是 隐藏的 当 点击页面中一条记录的详细信息的时候 弹出来 居中 ,然后再标题的地方点击鼠标整个div层可以再 屏幕内拖动(注意是屏幕内哦,就是div 边框到屏幕边的时候就过不去了)。层可以很容易弹出来 但是怎么拖动 我真的不知道 求教啊 求教。。

解决方案 »

  1.   

    <!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>
    这样试试
      

  2.   

    这么复杂的功能,有jquery插件可以做的