jquery實(shí)現(xiàn)彈出窗口效果的實(shí)例代碼
更新時(shí)間:2013年11月28日 09:35:51 作者:
這篇文章主要介紹了jquery實(shí)現(xiàn)彈出窗口效果的實(shí)例代碼。需要的朋友可以過來參考下,希望對(duì)大家有所幫助
JavaScript實(shí)現(xiàn)彈出窗口實(shí)質(zhì)上就是在瀏覽器上畫了一個(gè)方形區(qū)域,并在開始時(shí)將其隱藏,只是到某個(gè)JavaScript事件時(shí)才通過修改css的屬性值來將其顯示出來。
其大致步驟為:
•創(chuàng)建一個(gè)裝載彈出窗口的div
復(fù)制代碼 代碼如下:
<html>
<head>
<title>jQuery實(shí)例1:浮動(dòng)窗口</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<mce:script type="text/javascript" src="jslib/jquery.js" mce_src="jslib/jquery.js"></mce:script>
<mce:script type="text/javascript" src="jslib/jquerywin.js" mce_src="jslib/jquerywin.js"></mce:script>
<link type="text/css" rel="stylesheet" href="css/win.css" mce_href="css/win.css">
</head>
<body>
</body>
<a onclick="showWin()" href="#" mce_href="#">彈出窗口</a>
<div id="win">
<div id="title">我是標(biāo)題欄!<span id="close" onclick="hide()">X</span></div>
<div id="content">我是一個(gè)窗口!</div>
</div>
</html>
•創(chuàng)建相應(yīng)的css文件將其顯示為一個(gè)彈出窗口
復(fù)制代碼 代碼如下:
#win{
/*邊框*/
border:1px red solid;
/*窗口的高度和寬度*/
width : 300px;
height: 200px;
/*窗口的位置*/
position : absolute;
top : 100px;
left: 350px;
/*開始時(shí)窗口不可見*/
display : none;
}
/*控制背景色的樣式*/
#title{
background-color : blue;
color : red;
/*控制標(biāo)題欄的左內(nèi)邊距*/
padding-left: 3px;
}
#cotent{
padding-left : 3px;
padding-top : 5px;
}
/*控制關(guān)閉按鈕的位置*/
#close{
margin-left: 188px;
/*當(dāng)鼠標(biāo)移動(dòng)到X上時(shí),出現(xiàn)小手的效果*/
cursor: pointer;
}
•創(chuàng)建相應(yīng)的JavaScript文件來操作窗口的顯示
復(fù)制代碼 代碼如下:
function showWin(){
/*找到div節(jié)點(diǎn)并返回*/
var winNode = $("#win");
//方法一:利用js修改css的值,實(shí)現(xiàn)顯示效果
// winNode.css("display", "block");
//方法二:利用jquery的show方法,實(shí)現(xiàn)顯示效果
// winNode.show("slow");
//方法三:利用jquery的fadeIn方法實(shí)現(xiàn)淡入
winNode.fadeIn("slow");
}
function hide(){
var winNode = $("#win");
//方法一:修改css的值
//winNode.css("display", "none");
//方法二:jquery的fadeOut方式
winNode.fadeOut("slow");
//方法三:jquery的hide方法
winNode.hide("slow");
}
您可能感興趣的文章:
- Jquery實(shí)現(xiàn)自定義彈窗示例
- 小巧強(qiáng)大的jquery layer彈窗彈層插件
- jQuery實(shí)現(xiàn)彈窗居中效果類似alert()
- 運(yùn)用JQuery的toggle實(shí)現(xiàn)網(wǎng)頁加載完成自動(dòng)彈窗
- jquery模擬alert的彈窗插件
- jquery彈窗插件colorbox綁定動(dòng)態(tài)生成元素的方法
- jQuery實(shí)現(xiàn)簡(jiǎn)單彈窗遮罩效果
- jquery ezUI 雙擊行記錄彈窗查看明細(xì)的實(shí)現(xiàn)方法
- Jquery彈出窗口插件 LeanModal的使用方法
- jQuery+jqmodal彈出窗口實(shí)現(xiàn)代碼分明
- jQuery Mobile彈出窗、彈出層知識(shí)匯總
- jQuery實(shí)現(xiàn)的兩種簡(jiǎn)單彈窗效果示例
相關(guān)文章
JQuery以JSON方式提交數(shù)據(jù)到服務(wù)端示例代碼
這篇文章主要介紹了JQuery如何以JSON方式提交數(shù)據(jù)到服務(wù)端,需要的朋友可以參考下2014-05-05輕松使用jQuery雙向select控件Bootstrap Dual Listbox
這篇文章主要教大家如何輕松使用jQuery雙向select控件Bootstrap Dual Listbox,感興趣的小伙伴們可以參考一下2015-12-12