在前段頁(yè)面制作中,一個(gè)選項(xiàng)卡往往需要加載的內(nèi)容會(huì)很多,例如一些圖片站和特效站點(diǎn),過(guò)長(zhǎng)的加載和不完整的加載會(huì)給讀者很不好的體驗(yàn),這時(shí)候,如果我們?cè)诩虞d的過(guò)程中加入一個(gè)小小的設(shè)定,就是接下來(lái)要給大家展現(xiàn)的,loading等待加載提示,大家可以自由發(fā)揮把加載美化城進(jìn)度條也,用戶體驗(yàn)會(huì)更好一些。
不多羅嗦大家看效果吧
完成源碼:(ps:js文件真心貼不出來(lái),小編也很苦惱,需要還是留郵箱吧,小編保證,只是發(fā)源碼,絕不廣告騷擾)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>jquery css3頁(yè)面彈出loading加載</title>
</head>
<body>
<style type="text/css">
/* reset */
*{margin:0;padding:0;list-style-type:none;}
a{blr:expression(this.onFocus=this.blur())}/*去掉a標(biāo)簽的虛線框,避免出現(xiàn)奇怪的選中區(qū)域*/
:focus{outline:0;}
label{cursor:pointer;}
img{vertical-align:middle;}
table{empty-cells:show;border-collapse:collapse;border-spacing:0;}
h1{font-size:16px;}h2,h3,h4{font-size:14px;}h5,h6{font-size:12px;}
abbr,acronym{border:0;font-variant:normal}
address,caption,cite,code,dfn,em,th,var,optgroup{font-style:normal;font-weight:normal}
input,button,textarea,select,optgroup,option{font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit}
input,button,textarea,select{*font-size:100%}
a,img{border:0;}
a,a:visited{color:#5e5e5e; text-decoration:none;}
a:hover{color:#4183C4;text-decoration:underline;}
.clear{display:block;overflow:hidden;clear:both;height:0;line-height:0;font-size:0;}
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{display:inline-table;}/* Hides from IE-mac \*/
*html .clearfix{height:1%;}
.clearfix{display:block;}/* End hide from IE-mac */
*+html .clearfix{min-height:1%;}
body{font:12px/180% Arial,Lucida,Verdana,"宋體",Helvetica,sans-serif;color:#333;background:#fff;}
/* shortcut */
.shortcut{height:32px;line-height:32px;font-size:12px;background:#eee;text-transform:uppercase;box-shadow:1px 0px 2px rgba(0,0,0,0.2);border-bottom:1px solid #DDDDDD;}
.shortcut h1{font-size:14px;font-family:"微軟雅黑","宋體";}
.shortcut a,.shortcut h1{padding:0px 10px;letter-spacing:1px;color:#333;text-shadow:0px 1px 1px #fff;display:block;float:left;width:360px;height:32px;overflow:hidden;}
.shortcut a:hover{background:#fff;}
.shortcut span.right{float:right;display:inline-block;width:468px;height:15px;overflow:hidden;margin:8px 5px 0 0;}
.shortcut .close{
background:url(/Public/images/close-demo.gif) no-repeat 0 0;width:20px;height:20px;line-height:99em;overflow:hidden;display:inline-block;margin:6px 10px 0 10px;float:right;padding:0;
-webkit-transition:all .3s ease-out 0s;
-moz-transition:all .3s ease-out 0s;
-ms-transition:all .3s ease-out 0s;
-o-transition:all .3s ease-out 0s;
transition:all .3s ease-out 0s;
}
.shortcut .close:hover{background:url(/Public/images/close-demo.gif) no-repeat 0 -20px}
.shortcut .close:active{background:url(/Public/images/close-demo.gif) no-repeat 0 -40px}
</style>
<script type="text/javascript" src="./jquery css3頁(yè)面彈出loading加載代碼_files/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var iframeHeight=function () {
var _height=$(window).height() - 34;
$('#content').height(_height);
}
window.onresize=iframeHeight;
$(function () {
iframeHeight();
});
});
</script>
<div id="container" style="overflow:hidden;">
<iframe border="0" id="content" src="./jquery css3頁(yè)面彈出loading加載代碼_files/index.html" frameborder="0" height="100%" width="100%" style="height: 577px;"></iframe>
</div>
<script type="text/javascript">
var _bdhmProtocol=(("https:"==document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F382f81c966395258f239157654081890' type='text/javascript'%3E%3C/script%3E"));
</script>
<script src="./jquery css3頁(yè)面彈出loading加載代碼_files/h.js" type="text/javascript"></script>
</body>
</html>
天給大家介紹一個(gè)非常好用的前端插件jQuery UI。
jQuery UI是以 jQuery 為基礎(chǔ)的開(kāi)源 JavaScript 網(wǎng)頁(yè)用戶界面代碼庫(kù)。包含底層用戶交互、動(dòng)畫(huà)、特效和可更換主題的可視控件。
下面是一個(gè)以jQuery UI實(shí)現(xiàn)的彈出登錄框功能,代碼非常簡(jiǎn)單。
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/jquery-ui.css">
</head>
<body>
<h1>jQueryUI:Widgets —— Dialog</h1>
<h3>彈出式對(duì)話框</h3>
<a id="btn-login" class="btn btn-success" href="#">我要登錄</a>
<div id="dialog-login" title="用戶登錄">
<form action="">
用戶名:<input type="text"><br>
密碼名:<input type="password"><br>
</form>
</div>
<script src="js/jquery-1.11.3.js"></script>
<script src="JS/jquery-ui.js"></script>
<script>
var $dialog=$("#dialog-login")
$dialog.dialog({
autoOpen:false,
modal:false,
show:{effect:"blind",duration:1000},
hide:{effect:"explode",duration:1000},
buttons:{
"登錄":()=>setTimeout(()=>{
alert("登錄成功");
$dialog.dialog("close");
},1000),
"取消":()=>$dialog.dialog("close")
},
close(){
$("form").get(0).reset()
}
});
$("#btn-login").click(()=>{
$dialog.dialog("open")
})
</script>
</body>
</html>
<div class="subcategories">這里有點(diǎn)擊事件</div>
<div class="subcategories">這里有點(diǎn)擊事件</div>
<div class="subcategories">這里有點(diǎn)擊事件</div>
<script type="text/javascript">
//阻止點(diǎn)擊事件
$(function() {
$(".subcategories").click(function(event) {
event.stopPropagation();
});
});
</script>
么是JS事件冒泡?
在一個(gè)對(duì)象上觸發(fā)某類(lèi)事件(比如單擊onclick事件), 如果此對(duì)象定義了此事件的處理程序, 那么此事件就會(huì)調(diào)用這個(gè)處理程序, 如果沒(méi)有定義此事件處理程序或者事件返回true,
那么這個(gè)事件會(huì)向這個(gè)對(duì)象的父級(jí)對(duì)象傳播, 從里到外, 直至它被處理(父級(jí)對(duì)象所有同類(lèi)事件都將被激活), 或者它到達(dá)了對(duì)象層次的最頂層, 即document對(duì)象(有些瀏覽器是window)。
如何來(lái)阻止Jquery事件冒泡?
通過(guò)一個(gè)小例子來(lái)解釋
<!DOCTYPE html>
<html>
<head runat="server">
<title>Porschev---Jquery 事件冒泡</title>
<script src="jquery-1.3.2-vsdoc.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="divOne" onclick="alert('我是最外層');">
<div id="divTwo" onclick="alert('我是中間層!')">
<a id="hr_three" href="http://www.baidu.com" mce_href="http://www.baidu.com"onclick="alert('我是最里層!')">點(diǎn)擊我</a>
</div>
</div>
</form>
</body>
</html>
比如上面這個(gè)頁(yè)面,
分為三層:divOne是第外層,divTwo中間層,hr_three是最里層;
他們都有各自的click事件,最里層a標(biāo)簽還有href屬性。
運(yùn)行頁(yè)面,點(diǎn)擊“點(diǎn)擊我”,會(huì)依次彈出:我是最里層---->我是中間層---->我是最外層
---->然后再鏈接到百度.
這就是事件冒泡, 本來(lái)我只點(diǎn)擊ID為hr_three的標(biāo)簽, 但是確執(zhí)行了三個(gè)alert操作。
事件冒泡過(guò)程(以標(biāo)簽ID表示):hr_three----> divTwo----> divOne 。從最里層冒泡到最外層。
如何來(lái)阻止?
1.event.stopPropagation();
<script type="text/javascript">
$(function() {
$("#hr_three").click(function(event) {
event.stopPropagation();
});
});
<script>
再點(diǎn)擊"點(diǎn)擊我", 會(huì)彈出:我是最里層, 然后鏈接到百度
2.return false;
如果頭部加入的是以下代碼
<script type="text/javascript">
$(function() {
$("#hr_three").click(function(event) {
return false;
});
});
<script>
再點(diǎn)擊"點(diǎn)擊我", 會(huì)彈出:我是最里層, 但不會(huì)執(zhí)行鏈接到百度頁(yè)面
由此可以看出:
1.event.stopPropagation();
事件處理過(guò)程中,阻止了事件冒泡,但不會(huì)阻擊默認(rèn)行為(它就執(zhí)行了超鏈接的跳轉(zhuǎn))
2.return false;
事件處理過(guò)程中,阻止了事件冒泡,也阻止了默認(rèn)行為(比如剛才它就沒(méi)有執(zhí)行超鏈接的跳轉(zhuǎn))
還有一種有冒泡有關(guān)的:
3.event.preventDefault();
如果把它放在頭部A標(biāo)簽的click事件中, 點(diǎn)擊"點(diǎn)擊我"。
會(huì)發(fā)現(xiàn)它依次彈出:我是最里層---->我是中間層---->我是最外層, 但最后卻沒(méi)有跳轉(zhuǎn)到百度
它的作用是:事件處理過(guò)程中, 不阻擊事件冒泡, 但阻擊默認(rèn)行為(它只執(zhí)行所有彈框, 卻沒(méi)有執(zhí)行超鏈接跳轉(zhuǎn))
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。