GOOGLE的个性化主页拖搁功能的实例
作者:我就是个世界
发表于:2008-01-16
GOOGLE的个性化主页拖搁功能的实现方法,是用Jscript实现,不包含记忆功能,没有数据交换
其他效果和Google的个性化主页如出一辙,不错![emot]zan[/emot]
[html]
GOOGLE的个性化主页拖搁功能的实例
[/html]
[b][color=#FF0000]如运行错误 ,请复制下面代码到运行框中重新运行代码:[/color][/b][separator]
[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE> GOOGLE的个性化主页拖搁功能的实例 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
*{padding:0;margin:0}
body{font-family:Verdana,sans-serif;font-size:.7em;line-height:1.5em;margin:0; text-align:center;}
h3{ display:block; margin:10px; text-align:left; width:90%;}
h3 a{color:#3169b5;}
#Copy{border-top:#edf2fb 2px solid; width:90%; text-align:left; color:#666666;}
#Copy a{color:#3169b5; text-decoration:none;}
.dragTable{
border-top:1px solid #3366cc;
margin-bottom: 10px;
width:100%;
background-color:#FFFFFF;
}
td{vertical-align:top; }
ul{ padding:0; margin:0; list-style:none; }
li{ line-height:120%; color:#3169b5; }
.dragTR{
cursor:move;
color:#7787cc;
text-decoration:underline;
background-color:#e5eef9;
padding:10px 0 10px 5px;
font-weight:bold;
}
#parentTable{
border-collapse:collapse;
letter-spacing:25px;
}
</style>
<script defer language="jscript">
var Drag={dragged:false,
ao:null,
tdiv:null,
dragStart:function(){
Drag.ao=event.srcElement;
if((Drag.ao.tagName=="TD")||(Drag.ao.tagName=="TR")){
Drag.ao=Drag.ao.offsetParent;
Drag.ao.style.zIndex=100;
}else
return;
Drag.dragged=true;
Drag.tdiv=document.createElement("div");
Drag.tdiv.innerHTML=Drag.ao.outerHTML;
Drag.ao.style.border="1px dashed red";
Drag.tdiv.style.display="block";
Drag.tdiv.style.position="absolute";
Drag.tdiv.style.filter="alpha(opacity=70)";
Drag.tdiv.style.cursor="move";
Drag.tdiv.style.border="1px solid #000000";
Drag.tdiv.style.width=Drag.ao.offsetWidth;
Drag.tdiv.style.height=Drag.ao.offsetHeight;
Drag.tdiv.style.top=Drag.getInfo(Drag.ao).top;
Drag.tdiv.style.left=Drag.getInfo(Drag.ao).left;
document.body.appendChild(Drag.tdiv);
Drag.lastX=event.clientX;
Drag.lastY=event.clientY;
Drag.lastLeft=Drag.tdiv.style.left;
Drag.lastTop=Drag.tdiv.style.top;
},
draging:function(){//重要:判断MOUSE的位置
if(!Drag.dragged||Drag.ao==null)return;
var tX=event.clientX;
var tY=event.clientY;
Drag.tdiv.style.left=parseInt(Drag.lastLeft)+tX-Drag.lastX;
Drag.tdiv.style.top=parseInt(Drag.lastTop)+tY-Drag.lastY;
for(var i=0;i<parentTable.cells.length;i++){
var parentCell=Drag.getInfo(parentTable.cells[i]);
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
var subTables=parentTable.cells[i].getElementsByTagName("table");
if(subTables.length==0){
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
parentTable.cells[i].appendChild(Drag.ao);
}
break;
}
for(var j=0;j<subTables.length;j++){
var subTable=Drag.getInfo(subTables[j]);
if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
parentTable.cells[i].insertBefore(Drag.ao,subTables[j]);
break;
}else{
parentTable.cells[i].appendChild(Drag.ao);
}
}
}
}
}
,
dragEnd:function(){
if(!Drag.dragged)return;
Drag.dragged=false;
Drag.mm=Drag.repos(150,15);
Drag.ao.style.borderWidth="0px";
Drag.ao.style.borderTop="1px solid #3366cc";
Drag.tdiv.style.borderWidth="0px";
Drag.ao.style.zIndex=1;
},
getInfo:function(o){//取得坐标
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
},
repos:function(aa,ab){
var f=Drag.tdiv.filters.alpha.opacity;
var tl=parseInt(Drag.getInfo(Drag.tdiv).left);
var tt=parseInt(Drag.getInfo(Drag.tdiv).top);
var kl=(tl-Drag.getInfo(Drag.ao).left)/ab;
var kt=(tt-Drag.getInfo(Drag.ao).top)/ab;
var kf=f/ab;
return setInterval(function(){if(ab<1){
clearInterval(Drag.mm);
Drag.tdiv.removeNode(true);
Drag.ao=null;
return;
}
ab--;
tl-=kl;
tt-=kt;
f-=kf;
Drag.tdiv.style.left=parseInt(tl)+"px";
Drag.tdiv.style.top=parseInt(tt)+"px";
Drag.tdiv.filters.alpha.opacity=f;
}
,aa/ab)
},
inint:function(){//初始化
for(var i=0;i<parentTable.cells.length;i++){
var subTables=parentTable.cells[i].getElementsByTagName("table");
for(var j=0;j<subTables.length;j++){
if(subTables[j].className!="dragTable")break;
subTables[j].rows[0].className="dragTR";
subTables[j].rows[0].attachEvent("onmousedown",Drag.dragStart);
}
}
document.onmousemove=Drag.draging;
document.onmouseup=Drag.dragEnd;
}
//end of Object Drag
}
Drag.inint();
function _show(str){
var w=window.open('','');
var d=w.document;
d.open();
str=str.replace(/=(?!")(.*?)(?!")( |>)/g,"=\"$1\"$2");
str=str.replace(/(<)(.*?)(>)/g,"<span style='color:red;'><$2></span><br />");
str=str.replace(/\r/g,"<br />\n");
d.write(str);
}
</script>
</HEAD>
<BODY>
<div><h3> <a href="http://www.husw.net" target="_blank">Husw!OnRoad 在路上 www.husw.net</a></h3>
</div>
<table border="0" cellpadding="0" cellspacing="10" width="100%" id="parentTable">
<tr >
<td width="25%" valgin="top">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td><b>传说中的标题</b></td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题啊啊</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题2</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
<td width="25%">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题3</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题4</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题5</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
<td width="25%">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题6</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题7</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题8</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
</tr>
</table>
<div id="Copy">©2008 </div>
</BODY>
</HTML>
[/code]
其他效果和Google的个性化主页如出一辙,不错![emot]zan[/emot]
[html]
|
|
|
©2008
[/html]
[b][color=#FF0000]如运行错误 ,请复制下面代码到运行框中重新运行代码:[/color][/b][separator]
[code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE> GOOGLE的个性化主页拖搁功能的实例 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
*{padding:0;margin:0}
body{font-family:Verdana,sans-serif;font-size:.7em;line-height:1.5em;margin:0; text-align:center;}
h3{ display:block; margin:10px; text-align:left; width:90%;}
h3 a{color:#3169b5;}
#Copy{border-top:#edf2fb 2px solid; width:90%; text-align:left; color:#666666;}
#Copy a{color:#3169b5; text-decoration:none;}
.dragTable{
border-top:1px solid #3366cc;
margin-bottom: 10px;
width:100%;
background-color:#FFFFFF;
}
td{vertical-align:top; }
ul{ padding:0; margin:0; list-style:none; }
li{ line-height:120%; color:#3169b5; }
.dragTR{
cursor:move;
color:#7787cc;
text-decoration:underline;
background-color:#e5eef9;
padding:10px 0 10px 5px;
font-weight:bold;
}
#parentTable{
border-collapse:collapse;
letter-spacing:25px;
}
</style>
<script defer language="jscript">
var Drag={dragged:false,
ao:null,
tdiv:null,
dragStart:function(){
Drag.ao=event.srcElement;
if((Drag.ao.tagName=="TD")||(Drag.ao.tagName=="TR")){
Drag.ao=Drag.ao.offsetParent;
Drag.ao.style.zIndex=100;
}else
return;
Drag.dragged=true;
Drag.tdiv=document.createElement("div");
Drag.tdiv.innerHTML=Drag.ao.outerHTML;
Drag.ao.style.border="1px dashed red";
Drag.tdiv.style.display="block";
Drag.tdiv.style.position="absolute";
Drag.tdiv.style.filter="alpha(opacity=70)";
Drag.tdiv.style.cursor="move";
Drag.tdiv.style.border="1px solid #000000";
Drag.tdiv.style.width=Drag.ao.offsetWidth;
Drag.tdiv.style.height=Drag.ao.offsetHeight;
Drag.tdiv.style.top=Drag.getInfo(Drag.ao).top;
Drag.tdiv.style.left=Drag.getInfo(Drag.ao).left;
document.body.appendChild(Drag.tdiv);
Drag.lastX=event.clientX;
Drag.lastY=event.clientY;
Drag.lastLeft=Drag.tdiv.style.left;
Drag.lastTop=Drag.tdiv.style.top;
},
draging:function(){//重要:判断MOUSE的位置
if(!Drag.dragged||Drag.ao==null)return;
var tX=event.clientX;
var tY=event.clientY;
Drag.tdiv.style.left=parseInt(Drag.lastLeft)+tX-Drag.lastX;
Drag.tdiv.style.top=parseInt(Drag.lastTop)+tY-Drag.lastY;
for(var i=0;i<parentTable.cells.length;i++){
var parentCell=Drag.getInfo(parentTable.cells[i]);
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
var subTables=parentTable.cells[i].getElementsByTagName("table");
if(subTables.length==0){
if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
parentTable.cells[i].appendChild(Drag.ao);
}
break;
}
for(var j=0;j<subTables.length;j++){
var subTable=Drag.getInfo(subTables[j]);
if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
parentTable.cells[i].insertBefore(Drag.ao,subTables[j]);
break;
}else{
parentTable.cells[i].appendChild(Drag.ao);
}
}
}
}
}
,
dragEnd:function(){
if(!Drag.dragged)return;
Drag.dragged=false;
Drag.mm=Drag.repos(150,15);
Drag.ao.style.borderWidth="0px";
Drag.ao.style.borderTop="1px solid #3366cc";
Drag.tdiv.style.borderWidth="0px";
Drag.ao.style.zIndex=1;
},
getInfo:function(o){//取得坐标
var to=new Object();
to.left=to.right=to.top=to.bottom=0;
var twidth=o.offsetWidth;
var theight=o.offsetHeight;
while(o!=document.body){
to.left+=o.offsetLeft;
to.top+=o.offsetTop;
o=o.offsetParent;
}
to.right=to.left+twidth;
to.bottom=to.top+theight;
return to;
},
repos:function(aa,ab){
var f=Drag.tdiv.filters.alpha.opacity;
var tl=parseInt(Drag.getInfo(Drag.tdiv).left);
var tt=parseInt(Drag.getInfo(Drag.tdiv).top);
var kl=(tl-Drag.getInfo(Drag.ao).left)/ab;
var kt=(tt-Drag.getInfo(Drag.ao).top)/ab;
var kf=f/ab;
return setInterval(function(){if(ab<1){
clearInterval(Drag.mm);
Drag.tdiv.removeNode(true);
Drag.ao=null;
return;
}
ab--;
tl-=kl;
tt-=kt;
f-=kf;
Drag.tdiv.style.left=parseInt(tl)+"px";
Drag.tdiv.style.top=parseInt(tt)+"px";
Drag.tdiv.filters.alpha.opacity=f;
}
,aa/ab)
},
inint:function(){//初始化
for(var i=0;i<parentTable.cells.length;i++){
var subTables=parentTable.cells[i].getElementsByTagName("table");
for(var j=0;j<subTables.length;j++){
if(subTables[j].className!="dragTable")break;
subTables[j].rows[0].className="dragTR";
subTables[j].rows[0].attachEvent("onmousedown",Drag.dragStart);
}
}
document.onmousemove=Drag.draging;
document.onmouseup=Drag.dragEnd;
}
//end of Object Drag
}
Drag.inint();
function _show(str){
var w=window.open('','');
var d=w.document;
d.open();
str=str.replace(/=(?!")(.*?)(?!")( |>)/g,"=\"$1\"$2");
str=str.replace(/(<)(.*?)(>)/g,"<span style='color:red;'><$2></span><br />");
str=str.replace(/\r/g,"<br />\n");
d.write(str);
}
</script>
</HEAD>
<BODY>
<div><h3> <a href="http://www.husw.net" target="_blank">Husw!OnRoad 在路上 www.husw.net</a></h3>
</div>
<table border="0" cellpadding="0" cellspacing="10" width="100%" id="parentTable">
<tr >
<td width="25%" valgin="top">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td><b>传说中的标题</b></td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题啊啊</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题2</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
<td width="25%">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题3</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题4</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题5</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
<td width="25%">
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题6</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题7</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
<table border=0 class="dragTable" cellspacing="0">
<tr>
<td>传说中的标题8</td>
</tr>
<tr>
<td>
<ul>
<li>·Ajax: A New Approach to Web Applications</li>
<li>·Ajax: A New Approach to Web Applications</li>
</ul>
</td>
<tr>
</table>
</td>
</tr>
</table>
<div id="Copy">©2008 </div>
</BODY>
</HTML>
[/code]
请发表您的评论