JS彈出可拖拽可關(guān)閉的div層完整實(shí)例
來源:易賢網(wǎng) 閱讀:941 次 日期:2015-02-27 14:26:50
溫馨提示:易賢網(wǎng)小編為您整理了“JS彈出可拖拽可關(guān)閉的div層完整實(shí)例”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了JS彈出可拖拽可關(guān)閉的div層完整實(shí)現(xiàn)方法,包括對(duì)div彈出層的樣式及功能的實(shí)現(xiàn)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JS彈出可拖拽可關(guān)閉的div層完整實(shí)現(xiàn)方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>JS彈出可拖拽可關(guān)閉的div層</title>

<style>

html,body{height:100%;overflow:hidden;}

body,div,h2{margin:0;padding:0;}

body{font:12px/1.5 Tahoma;}

center{padding-top:10px;}

button{cursor:pointer;}

#win{position:absolute;top:50%;left:50%;width:400px;height:200px;background:#fff;border:4px solid #f90;margin:-102px 0 0 -202px;display:none;}

h2{font-size:12px;height:18px;text-align:right;background:#FC0;border-bottom:3px solid #f90;padding:5px;cursor:move;}

h2 span{color:#f90;cursor:pointer;background:#fff;border:1px solid #f90;padding:0 2px;}

</style>

<script>

window.onload = function ()

{

var oWin = document.getElementById("win");

var oBtn = document.getElementsByTagName("button")[0];

var oClose = document.getElementById("close");

var oH2 = oWin.getElementsByTagName("h2")[0];

var bDrag = false;

var disX = disY = 0;

oBtn.onclick = function ()

{

oWin.style.display = "block"

};

oClose.onclick = function ()

{

oWin.style.display = "none"

};

oClose.onmousedown = function (event)

{

(event || window.event).cancelBubble = true;

};

oH2.onmousedown = function (event)

{

var event = event || window.event;

bDrag = true;

disX = event.clientX - oWin.offsetLeft;

disY = event.clientY - oWin.offsetTop;

this.setCapture && this.setCapture();

return false

};

document.onmousemove = function (event)

{

if (!bDrag) return;

var event = event || window.event;

var iL = event.clientX - disX;

var iT = event.clientY - disY;

var maxL = document.documentElement.clientWidth - oWin.offsetWidth;

var maxT = document.documentElement.clientHeight - oWin.offsetHeight;

iL = iL < 0 ? 0 : iL;

iL = iL > maxL ? maxL : iL;

iT = iT < 0 ? 0 : iT;

iT = iT > maxT ? maxT : iT;

oWin.style.marginTop = oWin.style.marginLeft = 0;

oWin.style.left = iL + "px";

oWin.style.top = iT + "px";

return false

};

document.onmouseup = window.onblur = oH2.onlosecapture = function ()

{

bDrag = false;

oH2.releaseCapture && oH2.releaseCapture();

};

};

</script>

</head>

<body>

<div id="win"><h2><span id="close">×</span></h2></div>

<center><button>彈出層</button></center>

</body>

</html>

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

更多信息請查看IT技術(shù)專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機(jī)網(wǎng)站地址:JS彈出可拖拽可關(guān)閉的div層完整實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報(bào)名

  • 報(bào)班類型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)