jQuery實(shí)現(xiàn)的浮動(dòng)層div瀏覽器居中顯示效果
本文實(shí)例講述了jQuery實(shí)現(xiàn)的浮動(dòng)層div瀏覽器居中顯示效果。分享給大家供大家參考,具體如下:
1.在頁面的head中引入jQuery
<script type="text/javascript" language="javascript" src="jquery-1.7.2.min.js"></script>
2.在頁面的head中加入浮動(dòng)層和遮罩層的樣式
<style> #previewDiv{z-index: 9999;position:absolute;display:none;background:#fff;border-top:5px solid #999;border-bottom:7px solid #999;border-left:5px solid #999;border-right:7px solid #999;} .mask {color:#C7EDCC;background-color:#999;position:absolute;top:0px;left:0px;width:100%;height:3000px;opacity: 0.6;filter: "alpha(opacity=60)";filter: alpha(Opacity=60);} </style>
3.在頁面的底部加上浮動(dòng)的div
<div id="previewDiv"> <table id ="head"> <tr><td>短消息預(yù)覽</td></tr> </table> <table align="center"> <tr><td> <div class="zhnx_neirong"> <h3>您收到了來自腳本之家的回復(fù)</h3> <p class="duanluo"> 內(nèi)容:這是浮動(dòng)層居中的實(shí)例</span></p> </div> <div class="zhnx_huifu"><p><a href="javascript:open('http://chabaoo.cn/');">查看腳本之家</a></p></div> </td></tr> </table> <table align="center"> <tr><td><div><input type="button" value=" 關(guān) 閉 " onclick="hide();"/></div></td></tr> </table> </div>
4.添加顯示和隱藏的js函數(shù)
function show(){ //添加并顯示遮罩層 $("<div id='mask'></div>").addClass("mask").click(function() {}) .appendTo("body").fadeIn(0); document.getElementById("mask").style.display = "block"; var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#previewDiv").height(); var popupWidth = $("#previewDiv").width(); $("#previewDiv").css({ "position": "absolute", "top": (windowHeight-popupHeight)/2+$(document).scrollTop(), "left": (windowWidth-popupWidth)/2 }); $("#previewDiv").show(); } function hide(){ $("#mask").remove(); $("#previewDiv").hide(); }
完整實(shí)例代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <script type="text/javascript" language="javascript" src="jquery-1.7.2.min.js"></script> </head> <body> <style> #previewDiv{z-index: 9999;position:absolute;display:none;background:#fff;border-top:5px solid #999;border-bottom:7px solid #999;border-left:5px solid #999;border-right:7px solid #999;} .mask {color:#C7EDCC;background-color:#999;position:absolute;top:0px;left:0px;width:100%;height:3000px;opacity: 0.6;filter: "alpha(opacity=60)";filter: alpha(Opacity=60);} </style> <div id="previewDiv"> <table id ="head"> <tr><td>短消息預(yù)覽</td></tr> </table> <table align="center"> <tr><td> <div class="zhnx_neirong"> <h3>您收到了來自腳本之家的回復(fù)</h3> <p class="duanluo"> 內(nèi)容:這是浮動(dòng)層居中的實(shí)例</span></p> </div> <div class="zhnx_huifu"><p><a href="javascript:open('http://chabaoo.cn/');">查看腳本之家</a></p></div> </td></tr> </table> <table align="center"> <tr><td><div><input type="button" value=" 關(guān) 閉 " onclick="hide();"/></div></td></tr> </table> </div> <script type="text/javascript" language="javascript" > function show(){ //添加并顯示遮罩層 $("<div id='mask'></div>").addClass("mask").click(function() {}) .appendTo("body").fadeIn(0); document.getElementById("mask").style.display = "block"; var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $("#previewDiv").height(); var popupWidth = $("#previewDiv").width(); $("#previewDiv").css({ "position": "absolute", "top": (windowHeight-popupHeight)/2+$(document).scrollTop(), "left": (windowWidth-popupWidth)/2 }); $("#previewDiv").show(); } function hide(){ $("#mask").remove(); $("#previewDiv").hide(); } show(); </script> </body> </html>
運(yùn)行效果圖如下:
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery窗口操作技巧總結(jié)》、《jQuery拖拽特效與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jquery中Ajax用法總結(jié)》、《jQuery表格(table)操作技巧匯總》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動(dòng)畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery實(shí)現(xiàn)div浮動(dòng)層跟隨頁面滾動(dòng)效果
- jQuery實(shí)現(xiàn)的兼容性浮動(dòng)層示例
- jQuery實(shí)現(xiàn)浮動(dòng)層隨瀏覽器滾動(dòng)條滾動(dòng)的方法
- jQuery實(shí)現(xiàn)點(diǎn)擊按鈕彈出可關(guān)閉層的浮動(dòng)層插件
- jquery簡單的彈出層浮動(dòng)層代碼
- jQuery實(shí)現(xiàn)可拖動(dòng)的浮動(dòng)層完整代碼
- jQuery頁面滾動(dòng)浮動(dòng)層智能定位實(shí)例代碼
- 基于jquery的浮動(dòng)層效果代碼
- jQuery powerFloat萬能浮動(dòng)層下拉層插件使用介紹
- 基于JQuery的浮動(dòng)DIV顯示提示信息并自動(dòng)隱藏
- JQuery浮動(dòng)DIV提示信息并自動(dòng)隱藏的代碼
相關(guān)文章
淺談jQuery中 wrap() wrapAll() 與 wrapInner()的差異
本文結(jié)合W3School的文檔,分析了jQuery中 wrap() wrapAll() 與 wrapInner()的差異,并給出了圖文對(duì)比教程,非常的簡單實(shí)用,有需要的朋友可以參考下2014-11-11jQuery實(shí)現(xiàn)的placeholder效果完整實(shí)例
這篇文章主要介紹了jQuery實(shí)現(xiàn)的placeholder效果,可實(shí)現(xiàn)輸入框提示文字的功能,并且針對(duì)焦點(diǎn)的情況判定是否顯示,非常簡單實(shí)用,需要的朋友可以參考下2016-08-08jQuery實(shí)現(xiàn)三級(jí)菜單的代碼
上周新接手一個(gè)網(wǎng)站建設(shè)的活兒,其中有需要要jquery代碼實(shí)現(xiàn)三級(jí)菜單的需求,其實(shí)說難也不難,下面小編把代碼分享給大家,供大家參考2016-05-05jquery超簡單實(shí)現(xiàn)手風(fēng)琴效果的方法
這篇文章主要介紹了jquery超簡單實(shí)現(xiàn)手風(fēng)琴效果的方法,只需要幾行代碼即可實(shí)現(xiàn)手風(fēng)琴效果的樣式變換功能,需要的朋友可以參考下2015-06-06基于jquery的代碼顯示區(qū)域自動(dòng)拉長效果
今天看到一個(gè)技術(shù)類網(wǎng)站,在顯示代碼的地方,邊框會(huì)拉長,很方便用戶閱讀體驗(yàn),特看了下代碼,原理很簡單,使用了jquery,不適用也可以實(shí)現(xiàn)2011-12-12Jquery實(shí)現(xiàn)由下向上展開效果的例子
這篇文章主要介紹了Jquery實(shí)現(xiàn)由下向上展開效果的例子,本文同時(shí)講解了向下展開的例子,需要的朋友可以參考下2014-12-12jquery中animate的stop()方法作用實(shí)例分析
這篇文章主要介紹了jquery中animate的stop()方法作用,實(shí)例分析了animate的stop()方法在視頻播放代碼中的使用技巧,感興趣的朋友可以對(duì)比分析一下帶stop方法與不帶stop方法運(yùn)行效果的區(qū)別,需要的朋友可以參考下2015-01-01基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹形功能菜單
這篇文章主要介紹了基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹形功能菜單,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-06-06