类似Google个性首页的页面自定义拖拽布局 - IT生活资讯网 - 专注IT精品资讯 关注IT生活 提供丰富有价值的IT教程 - TechFeel.Com

摩族智能手机社区 动力互联科技提供带宽支持

中国IDC圈

手机频道智能手机 电子书 铃声 主题 游戏  IDC主机托管域名 空间 邮局 托管

 
您的位置:首页 > 网页设计 > Div+CSS >

类似Google个性首页的页面自定义拖拽布局

整理:互联网 来源:互联网我要收藏】 进入论坛 发布时间:2007-08-20 09:33:33

Google的个性首页大家应该有印象吧,自由的移动布局效果相当不错,国内已经有很多页面采用这种方法了,这里是类似Google个性首页的页面自定义拖拽布局的代码,如果有兴趣的朋友可以修改修改,结合一下Cookies就更加好了f5xTechFeel

 <html>f5xTechFeel
<head>f5xTechFeel
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />f5xTechFeel
<style>f5xTechFeel
body {margin:0px;padding:0px;font-size:12px;text-align:center;}f5xTechFeel
body > div {text-align:center; margin-right:auto; margin-left:auto;} f5xTechFeel
.content{width:900px;}f5xTechFeel
.content .left{f5xTechFeel
 float:left;f5xTechFeel
 width:20%;f5xTechFeel
 border:1px solid #FF0000;f5xTechFeel
 margin:3px;f5xTechFeel
}f5xTechFeel
.content .center{float:left;border:1px solid #FF0000;margin:3px;width:57%}f5xTechFeel
.content .right{float:right;width:20%;border:1px solid #FF0000;margin:3px}f5xTechFeel
.mo{height:auto;border:1px solid #CCC;margin:3px;background:#FFF}f5xTechFeel
.mo h1{background:#ECF9FF;height:18px;padding:3px;cursor:move}f5xTechFeel
.mo .nr{height:80px;border:1px solid #F3F3F3;margin:2px}f5xTechFeel
h1{margin:0px;padding:0px;text-align:left;font-size:12px}f5xTechFeel
</style>f5xTechFeel
<script>f5xTechFeel
var dragobj={}f5xTechFeel
window.onerror=function(){return false}f5xTechFeel
function on_ini(){f5xTechFeel
 String.prototype.inc=function(s){return this.indexOf(s)>-1?true:false}f5xTechFeel
 var agent=navigator.userAgentf5xTechFeel
 window.isOpr=agent.inc("Opera")f5xTechFeel
 window.isIE=agent.inc("IE")&&!isOprf5xTechFeel
 window.isMoz=agent.inc("Mozilla")&&!isOpr&&!isIEf5xTechFeel
 if(isMoz){f5xTechFeel
  Event.prototype.__defineGetter__("x",function(){return this.clientX+2})f5xTechFeel
  Event.prototype.__defineGetter__("y",function(){return this.clientY+2})f5xTechFeel
 }f5xTechFeel
 basic_ini()f5xTechFeel
}f5xTechFeel
function basic_ini(){f5xTechFeel
 window.$=function(obj){return typeof(obj)=="string"?document.getElementById(obj):obj}f5xTechFeel
 window.oDel=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}}f5xTechFeel
}f5xTechFeel
window.onload=function(){f5xTechFeel
 on_ini()f5xTechFeel
 var o=document.getElementsByTagName("h1")f5xTechFeel
 for(var i=0;i<o.length;i++){f5xTechFeel
  o[i].onmousedown=function(e){f5xTechFeel
   if(dragobj.o!=null)f5xTechFeel
    return falsef5xTechFeel
   e=e||eventf5xTechFeel
   dragobj.o=this.parentNodef5xTechFeel
   dragobj.xy=getxy(dragobj.o)f5xTechFeel
   dragobj.xx=new Array((e.x-dragobj.xy[1]),(e.y-dragobj.xy[0]))f5xTechFeel
   dragobj.o.style.width=dragobj.xy[2]+"px"f5xTechFeel
   dragobj.o.style.height=dragobj.xy[3]+"px"f5xTechFeel
   dragobj.o.style.left=(e.x-dragobj.xx[0])+"px"f5xTechFeel
   dragobj.o.style.top=(e.y-dragobj.xx[1])+"px"   f5xTechFeel
   dragobj.o.style.position="absolute"f5xTechFeel
   var om=document.createElement("div")f5xTechFeel
   dragobj.otemp=omf5xTechFeel
   om.style.width=dragobj.xy[2]+"px"f5xTechFeel
   om.style.height=dragobj.xy[3]+"px"f5xTechFeel
   dragobj.o.parentNode.insertBefore(om,dragobj.o)f5xTechFeel
   return falsef5xTechFeel
  }f5xTechFeel
 }f5xTechFeel
}f5xTechFeel
document.onselectstart=function(){return false}f5xTechFeel
window.onfocus=function(){document.onmouseup()}f5xTechFeel
window.onblur=function(){document.onmouseup()}f5xTechFeel
document.onmouseup=function(){f5xTechFeel
 if(dragobj.o!=null){f5xTechFeel
  dragobj.o.style.width="auto"f5xTechFeel
  dragobj.o.style.height="auto"f5xTechFeel
  dragobj.otemp.parentNode.insertBefore(dragobj.o,dragobj.otemp)f5xTechFeel
  dragobj.o.style.position=""f5xTechFeel
  oDel(dragobj.otemp)f5xTechFeel
  dragobj={}f5xTechFeel
 }f5xTechFeel
}f5xTechFeel
document.onmousemove=function(e){f5xTechFeel
 e=e||eventf5xTechFeel
 if(dragobj.o!=null){f5xTechFeel
  dragobj.o.style.left=(e.x-dragobj.xx[0])+"px"f5xTechFeel
  dragobj.o.style.top=(e.y-dragobj.xx[1])+"px"f5xTechFeel
  createtmpl(e)f5xTechFeel
 }f5xTechFeel
}f5xTechFeel
function getxy(e){f5xTechFeel
 var a=new Array()f5xTechFeel
 var t=e.offsetTop;f5xTechFeel
 var l=e.offsetLeft;f5xTechFeel
 var w=e.offsetWidth;f5xTechFeel
 var h=e.offsetHeight;f5xTechFeel
 while(e=e.offsetParent){f5xTechFeel
  t+=e.offsetTop;f5xTechFeel
  l+=e.offsetLeft;f5xTechFeel
 }f5xTechFeel
 a[0]=t;a[1]=l;a[2]=w;a[3]=hf5xTechFeel
  return a;f5xTechFeel
}f5xTechFeel
function inner(o,e){f5xTechFeel
 var a=getxy(o)f5xTechFeel
 if(e.x>a[1]&&e.x<(a[1]+a[2])&&e.y>a[0]&&e.y<(a[0]+a[3])){f5xTechFeel
  if(e.y<(a[0]+a[3]/2))f5xTechFeel
   return 1;f5xTechFeel
  elsef5xTechFeel
   return 2;f5xTechFeel
 }elsef5xTechFeel
  return 0;f5xTechFeel
}f5xTechFeel
function createtmpl(e){f5xTechFeel
 for(var i=0;i<12;i++){f5xTechFeel
  if($("m"+i)==dragobj.o)f5xTechFeel
   continuef5xTechFeel
  var b=inner($("m"+i),e)f5xTechFeel
  if(b==0)f5xTechFeel
   continuef5xTechFeel
  dragobj.otemp.style.width=$("m"+i).offsetWidthf5xTechFeel
  if(b==1){f5xTechFeel
   $("m"+i).parentNode.insertBefore(dragobj.otemp,$("m"+i))f5xTechFeel
  }else{f5xTechFeel
   if($("m"+i).nextSibling==null){f5xTechFeel
    $("m"+i).parentNode.appendChild(dragobj.otemp)f5xTechFeel
   }else{f5xTechFeel
    $("m"+i).parentNode.insertBefore(dragobj.otemp,$("m"+i).nextSibling)f5xTechFeel
   }f5xTechFeel
  }f5xTechFeel
  returnf5xTechFeel
 }f5xTechFeel
 for(var j=0;j<3;j++){f5xTechFeel
  if($("dom"+j).innerHTML.inc("div")||$("dom"+j).innerHTML.inc("DIV"))f5xTechFeel
   continuef5xTechFeel
  var op=getxy($("dom"+j))f5xTechFeel
  if(e.x>(op[1]+10)&&e.x<(op[1]+op[2]-10)){f5xTechFeel
   $("dom"+j).appendChild(dragobj.otemp)f5xTechFeel
   dragobj.otemp.style.width=(op[2]-10)+"px"f5xTechFeel
  }f5xTechFeel
 }f5xTechFeel
}f5xTechFeel
</script>f5xTechFeel
</head>f5xTechFeel
<body>f5xTechFeel
<div class=content>f5xTechFeel
 <div class=left id=dom0>f5xTechFeel
  <div class=mo id=m0>f5xTechFeel
   <h1>dom0</h1>f5xTechFeel
   <div class="nr"></div>f5xTechFeel
  </div>f5xTechFeel
  <div class=mo id=m1>f5xTechFeel
   <h1>dom1</h1><div class="nr"></div>f5xTechFeel
  </div>f5xTechFeel
  <div class=mo id=m2><h1>dom2</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m3><h1>dom3</h1><div class="nr"></div></div>f5xTechFeel
 </div>f5xTechFeel
 <div class=center id=dom1>f5xTechFeel
  <div class=mo id=m4><h1>dom4</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m5><h1>dom5</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m6><h1>dom6</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m7><h1>dom7</h1><div class="nr"></div></div>f5xTechFeel
 </div>f5xTechFeel
 <div class=right id=dom2>f5xTechFeel
  <div class=mo id=m8><h1>dom8</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m9><h1>dom9</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m10><h1>dom10</h1><div class="nr"></div></div>f5xTechFeel
  <div class=mo id=m11><h1>dom11</h1><div class="nr"></div></div>f5xTechFeel
 </div>f5xTechFeel
</div>f5xTechFeel
</body>f5xTechFeel
</html>

关键字: Google,个性首页,拖拽布局

评论】【 】【打印】【关闭

发表评论
用户名: 密码:
验证码: 匿名发表
TechFeel.Com 旗下网站:  摩族智能手机网 | 中国教程在线 | 动力互联科技
网站留言关于我们 | 广告服务| 合作媒体 | 联系我们 | 免责声明网站地图
Copyright © 2005 - 2007 All Rights Reserved
冀ICP备 05024357