javascript彈出可以拖動的視窗代碼執行個體

來源:互聯網
上載者:User

標籤:

<!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51texiao.cn/" /><title>可以拖動的快顯視窗-螞蟻部落</title> <style type="text/css"> #popDiv { position:absolute; visibility:hidden; overflow:hidden; border:2px solid #AEBBCA; background-color:#EEF1F8; cursor:move; padding:1px; } #popTitle { background:#9DACBF; height:20px; line-height:20px; padding:1px; } #popForm { padding:2px; } .title_left { font-weight:bold; padding-left:5px; float:left; } .title_right { float:right; } #popTitle .title_right a { color:#000; text-decoration:none; } #popTitle .title_right a:hover { text-decoration:underline; color:#FF0000; } </style> <script> function showPopup() //彈出層 { var objDiv=document.getElementById("popDiv"); objDiv.style.top="50px";//設定彈出層距離上邊界的距離  objDiv.style.left="200px";//設定彈出層距離左邊界的距離  objDiv.style.width="300px";//設定彈出層的寬度  objDiv.style.height="200px";//設定彈出層的高度  objDiv.style.visibility="visible"; } function hidePopup()//關閉層 { var objDiv=document.getElementById("popDiv"); objDiv.style.visibility="hidden"; } </script> </head> <body> <div id="popDiv"> <div id="popTitle"> <!-- 標題div --> <span class="title_left">修改操作</span> <span class="title_right" onClick="hidePopup()"><a href="#">關閉</a></span> </div> <div id="popForm"></div> </div> <input name="" type="button" onClick="showPopup()" value="操作" /> <script type="text/javascript"> var objDiv=document.getElementById("popDiv"); var isIE=document.all?true:false;//判斷瀏覽器類型 document.onmousedown = function(evnt)//當滑鼠左鍵按下後執行此函數 { var evnt=evnt?evnt:event; if(evnt.button == (document.all ? 1 : 0)) { mouseD = true;//mouseD為滑鼠左鍵狀態標誌,為true時表示左鍵被按下 } } objDiv.onmousedown = function(evnt) { objDrag=this;//objDrag為拖動的對象 var evnt=evnt?evnt:event; if(evnt.button == (document.all?1 : 0)) { mx=evnt.clientX; my=evnt.clientY; objDiv.style.left=objDiv.offsetLeft+"px"; objDiv.style.top=objDiv.offsetTop+"px"; if(isIE) { objDiv.setCapture(); } else { window.captureEvents(Event.MOUSEMOVE); } } } document.onmouseup=function() { mouseD=false; objDrag=""; if(isIE) { objDiv.releaseCapture(); } else { window.releaseEvents(objDiv.MOUSEMOVE); } } document.onmousemove=function(evnt) { var evnt=evnt?evnt:event; if(mouseD==true&&objDrag) { var mrx=evnt.clientX-mx; var mry=evnt.clientY-my; objDiv.style.left = parseInt(objDiv.style.left) + mrx + "px"; objDiv.style.top = parseInt(objDiv.style.top) + mry + "px"; mx = evnt.clientX; my = evnt.clientY; } } </script> </body> </html>

javascript彈出可以拖動的視窗代碼執行個體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.