DragClass.js[/code=JScript]
/*
Auth: jingliangliang
Date: 2008-5-5
Email: [email protected]
*/
(function(){
if(typeof Drag != "undefined")
{
var _Drag = Drag;
}
//此处声明Drag类
//--elementid:要移动元素的ID
var Drag = window.Drag = function(elementid){
var thisDrag = this;
this.DifWidth = 0;
this.DifHeight = 0;
this.thisDivDrag = document.getElementById(elementid);
this.thisDivDrag.onmousedown = function(event){
var theevent;
var theSrcevent;
if(window.event)
{
theevent = window.event;
theSrcevent = window.event.srcElement;
}
else
{
theevent =event;
theSrcevent =event.target;
}
thisDrag.DifWidth= theevent.clientX - theSrcevent.offsetLeft;
thisDrag.DifHeight = theevent.clientY - theSrcevent.offsetTop;
document.body.onmousemove =function(event){
var theevent;
if(window.event)
{
theevent = window.event;
}
else
{
theevent =event;
}
thisDrag.thisDivDrag.style.left = theevent.clientX -thisDrag.DifWidth ;
thisDrag.thisDivDrag.style.top = theevent.clientY -thisDrag.DifHeight ;
};
document.body.onmouseup =function(event)
{
document.body.onmousemove = "";
};
};
};
})();
[/code]--调用<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript" src="DragClass.js"></script>
<script type="text/javascript">
window.onload=function(){
__Drag = new Drag("div1");
};
</script>
</HEAD> <BODY>
<div id="div1" style="background-color:red;width:100px;height:100px;border:1px solid #666666;position: absolute;">test</div>
</BODY>
</HTML>
/*
Auth: jingliangliang
Date: 2008-5-5
Email: [email protected]
*/
(function(){
if(typeof Drag != "undefined")
{
var _Drag = Drag;
}
//此处声明Drag类
//--elementid:要移动元素的ID
var Drag = window.Drag = function(elementid){
var thisDrag = this;
this.DifWidth = 0;
this.DifHeight = 0;
this.thisDivDrag = document.getElementById(elementid);
this.thisDivDrag.onmousedown = function(event){
var theevent;
var theSrcevent;
if(window.event)
{
theevent = window.event;
theSrcevent = window.event.srcElement;
}
else
{
theevent =event;
theSrcevent =event.target;
}
thisDrag.DifWidth= theevent.clientX - theSrcevent.offsetLeft;
thisDrag.DifHeight = theevent.clientY - theSrcevent.offsetTop;
document.body.onmousemove =function(event){
var theevent;
if(window.event)
{
theevent = window.event;
}
else
{
theevent =event;
}
thisDrag.thisDivDrag.style.left = theevent.clientX -thisDrag.DifWidth ;
thisDrag.thisDivDrag.style.top = theevent.clientY -thisDrag.DifHeight ;
};
document.body.onmouseup =function(event)
{
document.body.onmousemove = "";
};
};
};
})();
[/code]--调用<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript" src="DragClass.js"></script>
<script type="text/javascript">
window.onload=function(){
__Drag = new Drag("div1");
};
</script>
</HEAD> <BODY>
<div id="div1" style="background-color:red;width:100px;height:100px;border:1px solid #666666;position: absolute;">test</div>
</BODY>
</HTML>
解决方案 »
- 请问超链接图片的切换的实现
- js面向对象编程问题,关于私有共有成员
- 关于显示隐藏二级目录的功能,用jQuery能够完全实现也可以。
- |zyciis| 求jquery 查询出没有for的label
- *******************************给小弟推荐个css进阶的好书或网站吧~~
- 如何判断一个字符串是合法IP地址段以下3种形式之一 a.b.c.d-e.f.g.h a.b.c.d/e.f.g.h and a.b.c.d/24
- 请高手帮助:如何移动FLASH标题的位置?
- javascript传参数问题
- 我想在进入一个窗体后再把本窗体的工具栏等去掉,该怎么做?
- 怎樣動態生成一個表格中的行﹖
- 输入框可以输入页可以选择、点选择js实现多选列表^_^
- 我共有7条数据 每页显示三条 但只能出来一页 而且 Ext.PagingToolbar显示共3条数据 是我查询语句有问题吗?
/*
Auth: jingliangliang
Date: 2008-5-5
Email: [email protected]
*/
(function(){
if(typeof Drag != "undefined")
{
var _Drag = Drag;
}
//此处声明Drag类
//--elementid:要移动元素的ID
var Drag = window.Drag = function(elementid){
var thisDrag = this;
this.DifWidth = 0;
this.DifHeight = 0;
this.thisDivDrag = document.getElementById(elementid);
this.thisDivDrag.onmousedown = function(event){
var theevent;
var theSrcevent;
if(window.event)
{
theevent = window.event;
theSrcevent = window.event.srcElement;
}
else
{
theevent =event;
theSrcevent =event.target;
}
thisDrag.DifWidth= theevent.clientX - theSrcevent.offsetLeft;
thisDrag.DifHeight = theevent.clientY - theSrcevent.offsetTop;
document.body.onmousemove =function(event){
var theevent;
if(window.event)
{
theevent = window.event;
}
else
{
theevent =event;
}
thisDrag.thisDivDrag.style.left = theevent.clientX -thisDrag.DifWidth ;
thisDrag.thisDivDrag.style.top = theevent.clientY -thisDrag.DifHeight ;
};
document.body.onmouseup =function(event)
{
document.body.onmousemove = "";
};
};
};
})();
要想什么拖动,直接传入ID就可以了。例如你的文章,直接传送文章所在的ID就可以使文章可以拖动啊
然后下面的输入框可以输入,内容都可以全选,不用于拖动就这样
[email protected]