jQuery之浮動(dòng)窗口實(shí)現(xiàn)代碼(兩種方法)
預(yù)覽:

Html代碼
<html>
<head>
<title>浮動(dòng)窗口</title>
<link type="text/css" rel="stylesheet" href="css/overflow.css" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/overflow.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var b = $("#b");
var overFlow = $("#over");
b.click(function(){
overFlow.fadeIn();
$("#mask").css("background","#111");
$("#mask").css("opacity","0.8");
})
$("#close").click(function(){
overFlow.fadeOut();
$("#mask").css("background","#fff");
$("#mask").css("opacity","1");
});
drag($("#over"),$("#title"));
}) ;
</script>
</head>
<body>
<div id="over">
<div id="title"><span id="t">這只是一個(gè)演示標(biāo)題</span><span id="close">[ x ]</span></div>
<div id="content">
When a container object, such as a div, has mouse capture, events originating on objects within that container are fired by the div, unless the bContainerCapture parameter of the setCapture method is set to false. Passing the value false causes the container to no longer capture all document events. Instead, objects within that container still fire events, and those events also bubble as expected.<br/>
---This is edited by Alp.
</div>
</div>
<div id="mask"> <a id="b" href="#">click</a></div>
</body>
</html>
Js代碼
function drag(overFlow,title){
title.onmousedown = function(evt){
var doc = document;
var evt = evt || window.event;
var x = evt.offsetX?evt.offsetX:evt.layerX;
var y = evt.offsetY?evt.offsetY:evt.layerY;
if(overFlow.setCapture){
overFlow.setCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
doc.onmousemove = function(evt){
evt = evt || window.event;
var xPosition = evt.pageX || evt.clientX;
var yPosition = evt.pageY || evt.clientY;
var newX = xPosition - x;
var newY = yPosition - y;
overFlow.style.left = newX;
overFlow.style.top = newY;
};
doc.onmouseup = function(){
if(overFlow.releaseCapture){
overFlow.releaseCapture();
}else if(window.captureEvents){
window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
}
doc.onmousemove=null;
doc.onmouseup=null;
};
};
}
css代碼
#over{
position: absolute;
left: 300px;
top: 200px;
border: 1px solid black;
display: none;
background: #cccccc;
cursor: default;
width: 300px;
z-index: 10;
opacity: 1;
}
#title{
border: 1px solid #1840C4;
background: #95B4DC;
padding: 2px;
font-size:12px;
cursor: default;
}
#close{
cursor: pointer;
margin-right: 1px;
overflow: hidden;
}
#content{
border: 1px solid #C2D560;
background: #EFF4D7;
}
#t{
margin-right:145px;
}
#mask{
z-index: 1;
background: #fff;
width: 1024px;
height: 800px;
}
#b{
position: absolute;
left: 200px;
top: 100px;
}
body{
padding: 0px;
margin: 0px;
}
#over{
background: transparent;
}
第二種方法:
消息框遮罩層:<iframe id="show_upload_iframe" frameborder=0 scrolling="no" style="display:none; position:absolute;"></iframe><div id="show_upload">nothing...</div>'
頁(yè)面加載loading中:<div id="body_loading" onClick="loaded();"><img src="__PUBLIC__/images/body_load.gif"></div>
關(guān)閉浮動(dòng)窗口:<a href="javascript:hideupload()">關(guān)閉窗口建議用小圖片</a>
打開(kāi)浮動(dòng)窗口:<a href="javascript:showupload('admin.php')">打開(kāi)浮動(dòng)</a>
// 消息框loading
function loading(){
var o = $('#body_loading');
o.css("left",(($(document).width())/2-(parseInt(o.width())/2))+"px");
o.css("top",(($(document).height()+$(document).scrollTop())/2-(parseInt(o.height())/2))+"px");
o.fadeIn("fast");
}
// 消息框消失
function loaded(){
var o = $('#body_loading');
o.fadeOut("fast");
}
// 隱藏浮動(dòng)窗口
function hideupload(){
$('#show_upload').hide();
$('#show_upload_iframe').hide();
}
// 彈出浮動(dòng)窗口
function showupload(ajaxurl){
loading();
var o=$('#show_upload');
var f=$('#show_upload_iframe');
var top = 200;
$.ajax({
url: ajaxurl,
//cache: false,
success: function(res){
loaded();
o.html(res);
o.css("left",(($(document).width())/2-(parseInt(o.width())/2))+"px");
if($(document).scrollTop()>200){
top = ($(document).height()+$(document).scrollTop())/2-(parseInt(o.height())/2);
}
o.css("top",top+"px");
f.css({'width':o.width(),'height':o.height(),'left':o.css('left'),'top':o.css('top')});
f.show();
o.show();
}
});
}
- jQuery實(shí)現(xiàn)彈出帶遮罩層的居中浮動(dòng)窗口效果
- JS簡(jiǎn)單實(shí)現(xiàn)浮動(dòng)窗口效果示例
- JS實(shí)現(xiàn)簡(jiǎn)單易用的手機(jī)端浮動(dòng)窗口顯示效果
- JavaScript實(shí)現(xiàn)上下浮動(dòng)的窗口效果代碼
- jquery實(shí)現(xiàn)浮動(dòng)在網(wǎng)頁(yè)右下角的彩票開(kāi)獎(jiǎng)公告窗口代碼
- JS實(shí)現(xiàn)彈出浮動(dòng)窗口(支持鼠標(biāo)拖動(dòng)和關(guān)閉)實(shí)例詳解
- JS實(shí)現(xiàn)可縮放、拖動(dòng)、關(guān)閉和最小化的浮動(dòng)窗口完整實(shí)例
- 多瀏覽器支持的右下角浮動(dòng)窗口
- JQuery 實(shí)現(xiàn)的頁(yè)面滾動(dòng)時(shí)浮動(dòng)窗口控件
- Android利用浮動(dòng)窗口提示用戶操作
相關(guān)文章
利用javascript/jquery對(duì)上傳文件格式過(guò)濾的方法
jquery中對(duì)上傳文件格式過(guò)濾的方法,需要的朋友參考下。2009-07-07jquery使用append(content)方法注意事項(xiàng)分享
append(content)函數(shù)的功能向每個(gè)匹配的元素內(nèi)部追加內(nèi)容,在使用方法上需要引起大家的注意,詳細(xì)看下面示例2014-01-01基于jQuery.Validate驗(yàn)證庫(kù)知識(shí)點(diǎn)的詳解
本篇文章介紹了,基于jQuery.Validate驗(yàn)證庫(kù)知識(shí)點(diǎn)的詳解。需要的朋友參考下2013-04-04jQuery中offsetParent()方法用法實(shí)例
這篇文章主要介紹了jQuery中offsetParent()方法用法,實(shí)例分析了offsetParent()方法的功能、定義及返回匹配元素所有祖先元素中第一個(gè)采用定位的祖先元素時(shí)的使用技巧,需要的朋友可以參考下2015-01-01Jquery簡(jiǎn)單分頁(yè)實(shí)現(xiàn)方法
這篇文章主要介紹了Jquery簡(jiǎn)單分頁(yè)實(shí)現(xiàn)方法,實(shí)例分析了jquery分頁(yè)的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07jquery實(shí)現(xiàn)輸入框動(dòng)態(tài)增減的實(shí)例代碼
主要功能是動(dòng)態(tài)增減輸入框,而且支持對(duì)各個(gè)輸入框的檢測(cè),每個(gè)輸入框在輸入內(nèi)容后,對(duì)其進(jìn)行錯(cuò)誤提示2013-07-07給jqGrid數(shù)據(jù)行添加修改和刪除操作鏈接(之一)
我這里用的不是jqGrid的自帶的編輯和刪除操作,我已經(jīng)把分頁(yè)導(dǎo)航欄下的編輯,刪除,搜索都取消掉了2011-11-11jQuery經(jīng)過(guò)一段時(shí)間自動(dòng)隱藏指定元素的方法
這篇文章主要介紹了jQuery經(jīng)過(guò)一段時(shí)間自動(dòng)隱藏指定元素的方法,實(shí)例分析了兩種比較常用的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03