iGoogle的模組拖動層拖動
<!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" />
<style type="text/css">
*{margin:0px; padding:0px;}
body{position:relative; width:780px; height:800px; border:1px solid red}
.drag{width:200px; height:100px; border:1px solid #000;margin:20px; background:#fff}
.drag h1{margin:0px; padding:0px; font-size:12px; height:18px; line-height:18px; background:#E0E7F3; text-indent:20px;cursor:move;}
.center{ margin:200px; border:3px solid red}
</style>
<script type="text/javascript"></script>
<title>iGoogle Div Drag 模組拖動</title>
</head>
<body>
<div class="drag" >
<h1><strong>popper.w'dragClass</strong></h1>
</div>
<div class="drag" >
<h1>www.999jiujiu.com</h1>
</div>
<div class="drag" >
<h1><strong>www.999jiujiu.com</strong></h1>
</div>
<div class="drag"><h1>測試二</h1></div>
<div class="drag"><h1>測試三</h1></div>
<div class="drag"><h1>測試四</h1></div>
<div class="drag"><h1>測試五</h1></div>
<div><A href="http://www.999jiujiu.com/">http://www.999jiujiu.com/</A></div>
</body>
</html>
<script type="text/javascript">
/*
Author : popper.w
Version : v2.0
*/
var DragZindexNumber=0;
function drag(obj){
var ox,oy,ex,xy,tag=0,mask=0;
if(tag==0){
obj.onmousedown=function(e)
{
if(mask==1){return; }
obj.style.zIndex=DragZindexNumber++;
transp(obj,"start")
tag=1;
var e = e||window.event;
ex=getEventOffset(e).offsetX;
ey=getEventOffset(e).offsetY;
ox=parseInt(obj.offsetLeft);
oy=parseInt(obj.offsetTop);
tempDiv=document.createElement("div");
with(tempDiv.style)
{
width=obj.offsetWidth+"px";
height=obj.offsetHeight+"px";
border="1px dotted red";
position="absolute";
left=obj.offsetLeft+"px";
top=obj.offsetTop+"px";
zIndex=999;
}
document.body.appendChild(tempDiv);
this.ele=tempDiv;
fDragStart(tempDiv);
document.body.onmousemove=function(e){
if(tag==1)
{
var e=e||window.event;
tempDiv.style.left=parseInt(e.clientX)-ex+"px";
tempDiv.style.top=parseInt(e.clientY)-ey+"px";
}
else{if(!tempDiv==null)tempDiv.parentNode.removeChild(tempDiv)}
}
tempDiv.onmouseup=function(e)
{
var e=e||window.event;
fDragEnd(tempDiv);
obj.style.position="absolute";
movie(obj,parseInt(e.clientX)-ex-19,parseInt(e.clientY)-ey-20);
tempDiv.parentNode.removeChild(tempDiv);
tag=0;
}
}
}
}
function movie(o,l,t){
var a=1;
mask=1;
var ol=parseInt(o.offsetLeft);
var ot=parseInt(o.offsetTop);
var iTimer=setInterval(function(){
if(a==10)
{
transp(o,"end");
mask=0;
clearInterval(iTimer);
}
o.style.left=ol+a*(l-ol)/10+"px";
o.style.top=ot+a*(t-ot)/10+"px";
a++;
},20);
}
function fCancleBubble(e)
{
var e = window.event || e;
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
}
function transp(o,mode){
if(mode=="start"){
if(document.all){
o.style.filter = "Alpha(Opacity=50)";
}else{
o.style.opacity = 0.5;
}
}
else {
if(document.all){
o.style.filter = "Alpha(Opacity=100)";
}else{
o.style.opacity = 1;
}
}
}
function getOffset(evt)
{
var target = evt.target;
if (target.offsetLeft == undefined)
{
target = target.parentNode;
}
var pageCoord = getPageCoord(target);
var eventCoord =
{
x: window.pageXOffset + evt.clientX,
y: window.pageYOffset + evt.clientY
};
var offset =
{
offsetX: eventCoord.x - pageCoord.x,
offsetY: eventCoord.y - pageCoord.y
};
return offset;
}
function getPageCoord(element)
{
var coord = {x: 0, y: 0};
while (element)
{
coord.x += element.offsetLeft;
coord.y += element.offsetTop;
element = element.offsetParent;
}
return coord;
}
function getEventOffset(evt)
{
var msg = "";
if (evt.offsetX == undefined)
{
var evtOffsets = getOffset(evt);
msg={offsetX:evtOffsets.offsetX,offsetY:evtOffsets.offsetY};
}
else
{
msg={offsetX:evt.offsetX,offsetY:evt.offsetY};
}
return msg;
}
function fDragStart(XEle)
{
switch(fCkBrs())
{
case 3:
window.getSelection().removeAllRanges();
break;
default:
XEle.setCapture();
break;
}
}
function fDragEnd(XEle)
{
switch(fCkBrs())
{
case 3:
window.getSelection().removeAllRanges();
break;
default:
XEle.releaseCapture();
break;
}
}
function fCkBrs()
{
switch (navigator.appName)
{
case 'Opera': return 2;
case 'Netscape': return 3;
default: return 1;
}
}
var element=document.getElementsByTagName("div");
for(var i=0;i<element.length;i++){
if(element[i].className=="drag"){
drag(element[i])}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
*{margin:0px; padding:0px;}
body{position:relative; width:780px; height:800px; border:1px solid red}
.drag{width:200px; height:100px; border:1px solid #000;margin:20px; background:#fff}
.drag h1{margin:0px; padding:0px; font-size:12px; height:18px; line-height:18px; background:#E0E7F3; text-indent:20px;cursor:move;}
.center{ margin:200px; border:3px solid red}
</style>
<script type="text/javascript"></script>
<title>iGoogle Div Drag 模組拖動</title>
</head>
<body>
<div class="drag" >
<h1><strong>popper.w'dragClass</strong></h1>
</div>
<div class="drag" >
<h1>www.999jiujiu.com</h1>
</div>
<div class="drag" >
<h1><strong>www.999jiujiu.com</strong></h1>
</div>
<div class="drag"><h1>測試二</h1></div>
<div class="drag"><h1>測試三</h1></div>
<div class="drag"><h1>測試四</h1></div>
<div class="drag"><h1>測試五</h1></div>
<div><A href="http://www.999jiujiu.com/">http://www.999jiujiu.com/</A></div>
</body>
</html>
<script type="text/javascript">
/*
Author : popper.w
Version : v2.0
*/
var DragZindexNumber=0;
function drag(obj){
var ox,oy,ex,xy,tag=0,mask=0;
if(tag==0){
obj.onmousedown=function(e)
{
if(mask==1){return; }
obj.style.zIndex=DragZindexNumber++;
transp(obj,"start")
tag=1;
var e = e||window.event;
ex=getEventOffset(e).offsetX;
ey=getEventOffset(e).offsetY;
ox=parseInt(obj.offsetLeft);
oy=parseInt(obj.offsetTop);
tempDiv=document.createElement("div");
with(tempDiv.style)
{
width=obj.offsetWidth+"px";
height=obj.offsetHeight+"px";
border="1px dotted red";
position="absolute";
left=obj.offsetLeft+"px";
top=obj.offsetTop+"px";
zIndex=999;
}
document.body.appendChild(tempDiv);
this.ele=tempDiv;
fDragStart(tempDiv);
document.body.onmousemove=function(e){
if(tag==1)
{
var e=e||window.event;
tempDiv.style.left=parseInt(e.clientX)-ex+"px";
tempDiv.style.top=parseInt(e.clientY)-ey+"px";
}
else{if(!tempDiv==null)tempDiv.parentNode.removeChild(tempDiv)}
}
tempDiv.onmouseup=function(e)
{
var e=e||window.event;
fDragEnd(tempDiv);
obj.style.position="absolute";
movie(obj,parseInt(e.clientX)-ex-19,parseInt(e.clientY)-ey-20);
tempDiv.parentNode.removeChild(tempDiv);
tag=0;
}
}
}
}
function movie(o,l,t){
var a=1;
mask=1;
var ol=parseInt(o.offsetLeft);
var ot=parseInt(o.offsetTop);
var iTimer=setInterval(function(){
if(a==10)
{
transp(o,"end");
mask=0;
clearInterval(iTimer);
}
o.style.left=ol+a*(l-ol)/10+"px";
o.style.top=ot+a*(t-ot)/10+"px";
a++;
},20);
}
function fCancleBubble(e)
{
var e = window.event || e;
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
}
function transp(o,mode){
if(mode=="start"){
if(document.all){
o.style.filter = "Alpha(Opacity=50)";
}else{
o.style.opacity = 0.5;
}
}
else {
if(document.all){
o.style.filter = "Alpha(Opacity=100)";
}else{
o.style.opacity = 1;
}
}
}
function getOffset(evt)
{
var target = evt.target;
if (target.offsetLeft == undefined)
{
target = target.parentNode;
}
var pageCoord = getPageCoord(target);
var eventCoord =
{
x: window.pageXOffset + evt.clientX,
y: window.pageYOffset + evt.clientY
};
var offset =
{
offsetX: eventCoord.x - pageCoord.x,
offsetY: eventCoord.y - pageCoord.y
};
return offset;
}
function getPageCoord(element)
{
var coord = {x: 0, y: 0};
while (element)
{
coord.x += element.offsetLeft;
coord.y += element.offsetTop;
element = element.offsetParent;
}
return coord;
}
function getEventOffset(evt)
{
var msg = "";
if (evt.offsetX == undefined)
{
var evtOffsets = getOffset(evt);
msg={offsetX:evtOffsets.offsetX,offsetY:evtOffsets.offsetY};
}
else
{
msg={offsetX:evt.offsetX,offsetY:evt.offsetY};
}
return msg;
}
function fDragStart(XEle)
{
switch(fCkBrs())
{
case 3:
window.getSelection().removeAllRanges();
break;
default:
XEle.setCapture();
break;
}
}
function fDragEnd(XEle)
{
switch(fCkBrs())
{
case 3:
window.getSelection().removeAllRanges();
break;
default:
XEle.releaseCapture();
break;
}
}
function fCkBrs()
{
switch (navigator.appName)
{
case 'Opera': return 2;
case 'Netscape': return 3;
default: return 1;
}
}
var element=document.getElementsByTagName("div");
for(var i=0;i<element.length;i++){
if(element[i].className=="drag"){
drag(element[i])}
}
</script>
相關文章
- JS實現拖動div層移動JS
- 可拖動模組控制元件控制元件
- 網頁模組拖動,Js仿Google和Windows Live的層拖拽網頁JSGoWindows
- jquery div層拖動效果封裝jQuery封裝
- angular 拖動功能Angular
- Unity 拖動UIUnityUI
- javacript 拖動 divJava
- C#實現窗體拖動、不允許窗體拖動、任意控制元件執行時拖動C#控制元件
- HTML元素拖動JSHTMLJS
- jquery拖動程式碼jQuery
- C#.WinForm 拖動檔案到PictrueBox(支援跨UAC拖動)C#ORM
- jQuery實現的自定義可以拖動的彈出層效果jQuery
- vueusejs實現拖動VueJS
- JavaScript左右拖動滑動的按鈕效果JavaScript
- JavaScript拖動調整元素的尺寸JavaScript
- JavaScript有虛線框的拖動JavaScript
- iOS UITableView 拖動排序的實現iOSUIView排序
- 按住panel 拖動窗體的方法
- Laravel-nova 增加拖動排序Laravel排序
- JavaScript 拖動調整元素尺寸JavaScript
- JavaScript 限定範圍拖動效果JavaScript
- JavaScript拖動div元素詳解JavaScript
- Windows拖動選單揭密 (轉)Windows
- 仿知乎拖動廣告的實現iOSiOS
- WIN98特殊視窗的動態拖動 (轉)
- 移動端觸屏拖動頁面滾動效果
- JavaScript表格tr行左右拖動效果JavaScript
- JavaScript拖動滑鼠繪製矩形方框JavaScript
- JavaScript滑鼠拖動調整div大小JavaScript
- canvas 按住滑鼠拖動 繪製文字Canvas
- antdv彈窗modal可拖動方法
- js拖動調整元素寬度JS
- PHP+jQuery-ui拖動浮動層排序並儲存到資料庫例項PHPjQueryUI排序資料庫
- MultiItem擴充套件 仿任務皮膚 跨多個RecyclerView的Item拖動 支援縮小後拖動套件View
- 10桌面圖示不能隨意拖動怎麼辦 win10桌面圖示不能拖動的方法Win10
- laravel-admin ModelTree 怎麼設定最大拖動層級Laravel
- SOLIDWORKS如何在裝配體中拖動下層零件Solid
- 可以拖動的div塊程式碼例項