html:
成都創(chuàng)新互聯(lián)于2013年開始,先為市中等服務(wù)建站,市中等地企業(yè),進行企業(yè)商務(wù)咨詢服務(wù)。為市中企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。<!DOCTYPE html> <html> <head> <meta charset= "utf-8"> <title></title> <!--<script src="jquery-1.9.1.min.js"></script>--> <style> #drag{ background: red; width: 200px; height: 200px; cursor: move; position: fixed; top: 0; left: 0; } </style> </head> <body> <div id="drag"></div> <script src="scripts/test.js"></script> </body> </html>
js:
window.onload = function(){ var drag = new Drag("drag"); drag.init(); } //獲取瀏覽器窗口寬度 function getInner(){ var pageWidth = window.innerWidth; var pageHeight = window.innerHeight; if(typeof pageWidth != "number"){ if(document.compatMode == "CSS1Compat"){ pageWidth = document.documentElement.clientWidth; pageHeight = document.documentElement.clientHeight; }else { pageWidth = document.body.clientWidth; pageHeight = document.body.clientHeight; } } return {width:pageWidth,height:pageHeight}; } //構(gòu)造函數(shù) function Drag(id){ this.obj = document.getElementById("drag"); this.disx = 0; this.disy = 0; } Drag.prototype.init = function(){ //this 指針 var me = this; this.obj.||event; me.onmouseDown(e); //阻止默認事件 return false; } } Drag.prototype.onmouseDown = function(e){ //this指針 var me = this; this.disx = e.clientX - this.obj.offsetLeft; this.disy = e.clientY - this.obj.offsetTop; document.||event; me.onmouseMove(e); } document.onmouseup = function(){ me.mouseUp(); } } Drag.prototype.onmouseMove = function (e){ //this指針 var lf = e.clientX - this.disx; var tp = e.clientY - this.disy; if(lf < 0){ //防止拖曳層超出左邊界 lf = 0; }else if(lf > getInner().width - this.obj.offsetWidth){ lf = getInner().width - this.obj.offsetWidth;//防止拖曳層超出右邊界 } if(tp < 0){ tp = 0;//防止拖曳層超出上邊界 }else if(tp > getInner().height - this.obj.offsetHeight){ tp = getInner().height - this.obj.offsetHeight;//防止拖曳層超出下邊界 } this.obj.style.left = lf + 'px'; this.obj.style.top = tp + 'px'; }; Drag.prototype.mouseUp = function (){ document.onmousemove = null; document.onmouseup = null; };
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
當前名稱:js面向?qū)ο缶毩暎ㄒ唬和弦沸Ч?創(chuàng)新互聯(lián)
路徑分享:http://muchs.cn/article34/hiise.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、移動網(wǎng)站建設(shè)、網(wǎng)站維護、網(wǎng)站設(shè)計、App設(shè)計、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容