1.这个是我从网上找的,找了好久
<script type="text/javascript">
var _move=false;//移动标记
var _x,_y;//鼠标离控件左上角的相对位置
$(document).ready(function()
{
$("#login_pop").click(function(){
}).mousedown(function(e){
_move=true;
_x=e.pageX-parseInt($("#login_pop").css("left"));
_y=e.pageY-parseInt($("#login_pop").css("top"));
// $("#login_pop").fadeTo(20, 0.25);//点击后开始拖动并透明显示
});
$(document).mousemove(function(e){
if(_move)
{
var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
var y=e.pageY-_y;
$("#login_pop").css({top:y,left:x});//控件新位置
}
}).mouseup(function()
{
_move=false;
// $("#login_pop").fadeTo("fast", 1);//松开鼠标后停止移动并恢复成不透明
});
});
</script>
2.这个是我的同事写的
script type="text/javascript">
$(function(){
var x, y, i=1;
$(".WindowDrag")
.mouseover(function(){ //鼠标悬浮的动作开始↓
$(this).css("cursor","move"); //把鼠标的形状换成可移动十字图标
}) //鼠标悬浮的动作结束↑
.mousedown(function(e){ //鼠标按下的动作开始↓
$(this).css("position", "absolute");
$(this).css("opacity", "0.8");
$(this).css("z-index", 9999); //把当前的模块设置为最前面
var offset = $(this).offset(); //获取当前模块的坐标
x = e.pageX - offset.left; //计算当前模块和当前鼠标的相对位置
y = e.pageY - offset.top;
$(this).bind("mousemove",function(ev){ //绑定鼠标移动时的动作
var _x = ev.pageX - x; //让当前模块跟着鼠标移动
var _y = ev.pageY - y;
$(this).css({"left":_x, "top":_y});
});
}) //鼠标按下的动作结束↑
.mouseup(function(){ //鼠标弹起的动作开始↓
$(this).unbind("mousemove"); //解绑鼠标移动功能
$(this).css("opacity", "1");
$(this).css("z-index", 10); //还原模块优先级
}) //鼠标弹起的动作结束↑
.mouseout(function(){ //鼠标移出的动作开始↓
// $(this).unbind("mousemove"); //取消当前模块的鼠标移动事件
// $(this).css("z-index", 10); //还原模块优先级
}); //鼠标移出的动作结束↑
});
</script>
写的差不多 但是很有用,自己还可以加很多的效果