貼代碼
復制代碼 代碼如下:<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<title>彈出窗口_www
<link type="text/css" rel="stylesheet" href="window
<script language="javascript" type="text/javascript" src="
<script language="javascript" type="text/javascript" src="window
<script language="javascript">
$(document)
$("#btn_center")
$(window)
popcenterWindow();
});
});
$("#btn_right")
$(window)
poprightWindow();
});
});
$("#btn_left")
$(window)
popleftWindow();
});
});
});
</script>
</head>
<body>
<input type="button" value="彈出居中的窗口" id="btn_center">
<input type="button" value="彈出居右的窗口" id="btn_right">
<input type="button" value="彈出居左的窗口" id="btn_left">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class="window" id="center">
<div class="title"><img src="close
<div class="content">哈哈哈哈哈哈哈</div>
</div>
<div class="window" id="right">
<div class="title"><img src="close
<div class="content">哈哈哈哈哈哈哈</div>
</div>
<div class="window" id="left">
<div class="title"><img src="close
<div class="content">哈哈哈哈哈哈哈</div>
</div>
</body>
</html>
JS
//窗口的高度
var windowHeight;
//窗口的寬度
var windowWidth;
//彈窗的高度
var popHeight;
//彈窗的寬度
var popWidth;
//滾動條滾動的高度
var scrollTop;
//滾動條滾動的寬度
var scrollleft;
//延時的時間
var timeout;
function init(){
//獲得窗口的高度
windowHeight=$(window)
//獲得窗口的寬度
windowWidth=$(window)
//獲得彈窗的高度
popHeight=$("
//獲得彈窗的寬度
popWidht=$("
//獲得滾動條的高度
scrollTop=$(window)
//獲得滾動條的寬度
scrollleft=$(window)
}
//定義關閉窗口
function closeWindow(){
$("
$(this)
});
}
//定義彈出窗口的方法
function popcenterWindow(){
//先清空上一次的延遲
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=(windowHeight
var popX=(windowWidth
$("#center")
closeWindow();
}
function popleftWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=windowHeight+scrollTop
var popX=scrollleft
$("#left")
closeWindow();
}
function poprightWindow(){
clearTimeout(timeout);
timeout=setTimeout(function (){
init();
var popY=windowHeight
var popX=windowWidth
$("#right")
closeWindow();
}
CSS
<SPAN style="FONT
width:
background
padding:
margin:
position:absolute;
display:none;
}
height:
background
padding:
font
overflow:auto;
}
padding:
color:#
font
}
float:right;
cursor:pointer;
}</SPAN>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19817.html