具体代码如下所示:
$('#showTitle ').鼠标向下(函数(e){ v tool=true;VH hThEr=e . PageyvWidth=e . page xcheight=VH h8-$(' # show ').偏移量()。顶部;cWdith=vWidth - $('#show ').偏移量()。向左;//alert('divshow' $('#show ').偏移量()。top ' div VH h8 ' VH h8);//alert('高谢克特宽cWdith);}) $(文档)。鼠标上移(function(){ vbool=false;}) var showWidth=$('#show ').宽度();var showHeight=$('#show ').高度();var documentWidth=$(文档)。宽度();var documentHeight=$(文档)。高度();$(文档)。鼠标移动(函数{ if(vbool){ var div height=e . Pagey-Cheight;//窗口要移动到的位置var div width=e . PageX-CwDITH;//窗口要移动到的位置$('#la1 ').文本(div高度' w ' div宽度' win '显示宽度' x '文档宽度' '显示宽度);if(div width 0){ div width=0;} if(div高度50){ div高度=50;} if(div width文档宽度-显示宽度){ div width=文档宽度-显示宽度-5;} if(div height文档高度-显示高度){ div height=文档高度-显示高度-5;} $(“# show”).css({ 'left': divwidth,' top ' : div height });} })下面看下jQuery鼠标拖拽移动窗口的实现代码
拖拽移动需要注意的是:拖拽移动的窗口是如何定位的,如果向左属性为'%' ,以左边距来计算定位,如下实例,如果向左属性为数字,直接使用向左即可。
//弹窗模块拖拽拖动$(function(){ var _ move=false;//移动标记var _x,_ y;//鼠标离控件左上角的相对位置var _dragZone=$(' .M_boxCenter .H3’;var _拖拽体=_拖拽区。parent();_dragZone.mousedown(函数(e){ $(本)).attr('onselectstart ',' return false ');//禁双击选中$(“正文”).CSS({ '-web kit-user-select ' : ' none ','-moz-user-select':'none ','-ms-user-select':'none ','-khtml-user-select':'none ',' user-select ' : ' none ' });//禁止选中文字_ move=true _ x=e . PageX-ParSeint(_ DragBody。CSS('左边距');_ y=e . Pagey-ParSeint(_ DragBody。CSS('页边距-顶部');_dragBody.fadeTo(150,0.5);});$(文档)。鼠标移动(函数(e){ if(_ move){ var x=e . pagex-_ x;//移动时根据鼠标位置计算控件左上角的绝对位置var y=e . Pagey-_ y;if(e . PageX=0 | | e . PageY=0){ _ move=false;} else { _ DragBody。CSS({左边距: x,右边距至p :y });//控件新位置} } }).鼠标上移(function(){ _ move=false;_dragBody.fadeTo('fast ',1);$(“正文”).移除attr(' style ');//移除不能选文字});});以上所述是小编给大家介绍的jQuery窗口拖动功能的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我们网站的支持!