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>http://www.999jiujiu.com/</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>

时间: 2024-08-29 19:52:41

iGoogle的模块拖动层拖动的相关文章

拖动层 拖动div 封装js 貌似不兼容FF,郁闷

原文发布时间为:2009-12-02 -- 来源于本人的百度文章 [由搬家工具导入] <!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"><he

JavaScript:Div层拖动效果

Div层拖动效果图: 实现: CSS: <style> div { position:relative; } </style> JS: <script type="text/javascript"> var mouseover=true var xcoor; var ycoor; function coordinates() { if (event.srcElement.id.indexOf("wishbroad") == 0)

jQuery制作div板块拖动层排序

html结构: <!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="

js拖动层

模仿网易彩票网(http://caipiao.163.com/)的登陆框自己做了一个拖动层,不过有点小问题——在谷歌浏览拖动的时候鼠标状态变成了文字状态(cursor:text;) 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xml

完整的网页浮动层拖动实例代码

一个供学习不错的网页拖动层,具有丰富的层拖动设置功能,比如可设置拖动的范围.垂直.水平方向拖动,是否透明显示层等,运用JS和CSS等实现的HTML层拖动网页,代码完整:前端框架资源分享 .代码   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html

js拖动层原形版

脚本文件: function JzDrag(moveDivId, moveDivHandle) { // var me = this; this.M = false; //是否在移动对象 this.DX = { x: 0, y: 0 }; //保存起始位置和元素的位置差 this.Div = document.getElementById(moveDivId); //移动对象 this.Handle = moveDivHandle ? document.getElementById(moveDi

漂亮的Js拖动层,窗口拖拽(改变大小/最小化/最大化/还原/关闭)

<!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-

Js代码动态移动层-拖动浮层并关闭

<html><head><title>动态移动的层</title><body bgcolor="#ADBAC9"><div  id="div1" class="yellow" style="VISIBILITY:visible ; background-color:#FFFF00; position: absolute; top: 60; left: 200; width

JavaWeb网上图书商城完整项目--21.用户模块各层相关类的创建

1.现在要为user用户模块创建类 用户模块功能包括:注册.激活.登录.退出.修改密码. User类对照着t_user表来写即可.我们要保证User类的属性名称与t_user表的列名称完全相同. 我们来创建User类 package com.weiyuan.goods.user.domian; public class User { private String uid; //主键 private String loginname;// 登陆名称 private String loginpass