當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JS通用窗口拖动函数
生活随笔
收集整理的這篇文章主要介紹了
JS通用窗口拖动函数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<script language="JavaScript" type="text/javascript">// 點擊拖動窗口- 調用請使用: οnmοusedοwn='Move_obj("objId")' objId: 表示你想拖動的窗口IDvar drag_=false;//獲取輸入:ID, 獲得objId對象var D=new Function('obj','return document.getElementById(obj);');var oevent=new Function('e','if (!e) e = window.event;return e');var obj_move=false;function Move_obj(obj){var x,y;obj_move=true;//注冊obj對象鼠標按下事件D(obj).οnmοusedοwn=function(e){//取消拖動if(!obj_move)return false;drag_=true;//with(this): 為區(qū)域語句設定默認對象。style等價于 this.stylewith(this){//obj對象offsetLeft距離左邊距離 不包括marginLeft寬度, offsetTop同理style.position="absolute";var temp1=offsetLeft;var temp2=offsetTop;//clientX 事件屬性返回當事件被觸發(fā)時鼠標指針向對于瀏覽器頁面(或當前窗口)的水平坐標。x=oevent(e).clientX;y=oevent(e).clientY;document.οnmοusemοve=function(e){//取消拖動if(!drag_)return false;with(this){//obj距離左邊距離 + 外邊距 + 鼠標移動距離style.left=temp1-Number(style.marginLeft.substring(0,style.marginLeft.length-2))+oevent(e).clientX-x+"px";style.top=temp2-Number(style.marginTop.substring(0,style.marginTop.length-2)) +oevent(e).clientY-y+"px";}}}document.οnmοuseup=new Function("drag_=false;obj_move=false;");}}</script>
轉載于:https://www.cnblogs.com/henw/archive/2011/06/23/2088248.html
總結
以上是生活随笔為你收集整理的JS通用窗口拖动函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中文信息匮乏年代,新媒体粉墨登场
- 下一篇: apache的斜杠问题