jquery animate實現(xiàn)鼠標(biāo)放上去顯示離開隱藏效果
更新時間:2013年07月21日 17:53:06 作者:
本文為大家介紹下使用jquery animate實現(xiàn)鼠標(biāo)放上去顯示,離開就隱藏的效果,感興趣的朋友可以參考下哈,希望對大家有所幫助
1、CSS樣式:
@CHARSET "UTF-8";
* html .showbox,* html .overlay {
position: absolute;
top: expression(eval(document.documentElement.scrollTop) );
}
#AjaxLoading {
border: 1px solid #8CBEDA;
color: #37a;
font-size: 12px;
font-weight: bold;
}
#AjaxLoading div.loadingWord {
width: 180px;
height: 50px;
line-height: 50px;
border: 2px solid #D6E7F2;
background: #fff;
}
#AjaxLoading img {
margin: 10px 15px;
float: left;
display: inline;
}
.overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 998;
width: 100%;
height: 100%;
_padding: 0 20px 0 0;
background: #f6f4f5;
display: none;
}
.showbox {
position: fixed;
top: 0;
left: 50%;
z-index: 9999;
opacity: 0;
filter: alpha(opacity = 0);
margin-left: -80px;
}
2、JS:
/**
* 加載動畫窗口
*
* @author dendy
* @since 2013-7-19 10:13:05
*/
function getLoadingHtml(msg) {
if(!msg) msg = "加載";
var html = "<div id='loadingDiv'>"
+ "<div style='height: 1325px; display: none; opacity: 0;' class='overlay'></div>"
+ "<div style='opacity: 0; margin-top: 250px;' id='AjaxLoading' class='showbox'>"
+ "<div class='loadingWord'>"
+ "<img src='" + Util.getContentPath() +"/images/ajax-loader.gif'>" + msg + "中,請稍候..."
+ "</div>"
+ "</div>"
+ "<div style='height: 1200px;'></div>"
+ "</div>";
return html;
}
function ajaxLoadingInit(msg) {
var loadingDiv = getLoadingHtml(msg);
var h = $(document).height();
$(".overlay").css({"height": h});
var div = $("body").find("#loadingDiv");
div.remove();
$("body").append($(loadingDiv));
}
/**
* 開始顯示loading,在ajax執(zhí)行之前調(diào)用
* @param msg 操作消息,"加載", "保存", "刪除"
*/
function startLoading(msg) {
ajaxLoadingInit(msg);
$(".overlay").css({'display':'block','opacity':'0.8'});
$(".showbox").stop(true).animate({'margin-top':'300px','opacity':'1'},200);
}
/**
* 加載完成后隱藏,在ajax執(zhí)行完成后(complete)調(diào)用
*/
function endLoading() {
$(".showbox").stop(true).animate({'margin-top':'250px','opacity':'0'},400);
$(".overlay").css({'display':'none','opacity':'0'});
}
3、調(diào)用例子:
startLoading();
$.ajax({
type : "POST",
url : this.url,
dataType : "json",
data : this.args,
success : function (data) {
},
complete : function () {
if (self.showLoading == true) endLoading();
},
error : this.error
});
復(fù)制代碼 代碼如下:
@CHARSET "UTF-8";
* html .showbox,* html .overlay {
position: absolute;
top: expression(eval(document.documentElement.scrollTop) );
}
#AjaxLoading {
border: 1px solid #8CBEDA;
color: #37a;
font-size: 12px;
font-weight: bold;
}
#AjaxLoading div.loadingWord {
width: 180px;
height: 50px;
line-height: 50px;
border: 2px solid #D6E7F2;
background: #fff;
}
#AjaxLoading img {
margin: 10px 15px;
float: left;
display: inline;
}
.overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 998;
width: 100%;
height: 100%;
_padding: 0 20px 0 0;
background: #f6f4f5;
display: none;
}
.showbox {
position: fixed;
top: 0;
left: 50%;
z-index: 9999;
opacity: 0;
filter: alpha(opacity = 0);
margin-left: -80px;
}
2、JS:
復(fù)制代碼 代碼如下:
/**
* 加載動畫窗口
*
* @author dendy
* @since 2013-7-19 10:13:05
*/
function getLoadingHtml(msg) {
if(!msg) msg = "加載";
var html = "<div id='loadingDiv'>"
+ "<div style='height: 1325px; display: none; opacity: 0;' class='overlay'></div>"
+ "<div style='opacity: 0; margin-top: 250px;' id='AjaxLoading' class='showbox'>"
+ "<div class='loadingWord'>"
+ "<img src='" + Util.getContentPath() +"/images/ajax-loader.gif'>" + msg + "中,請稍候..."
+ "</div>"
+ "</div>"
+ "<div style='height: 1200px;'></div>"
+ "</div>";
return html;
}
function ajaxLoadingInit(msg) {
var loadingDiv = getLoadingHtml(msg);
var h = $(document).height();
$(".overlay").css({"height": h});
var div = $("body").find("#loadingDiv");
div.remove();
$("body").append($(loadingDiv));
}
/**
* 開始顯示loading,在ajax執(zhí)行之前調(diào)用
* @param msg 操作消息,"加載", "保存", "刪除"
*/
function startLoading(msg) {
ajaxLoadingInit(msg);
$(".overlay").css({'display':'block','opacity':'0.8'});
$(".showbox").stop(true).animate({'margin-top':'300px','opacity':'1'},200);
}
/**
* 加載完成后隱藏,在ajax執(zhí)行完成后(complete)調(diào)用
*/
function endLoading() {
$(".showbox").stop(true).animate({'margin-top':'250px','opacity':'0'},400);
$(".overlay").css({'display':'none','opacity':'0'});
}
3、調(diào)用例子:
復(fù)制代碼 代碼如下:
startLoading();
$.ajax({
type : "POST",
url : this.url,
dataType : "json",
data : this.args,
success : function (data) {
},
complete : function () {
if (self.showLoading == true) endLoading();
},
error : this.error
});
您可能感興趣的文章:
- jQuery實現(xiàn)鼠標(biāo)滑過鏈接控制圖片的滑動展開與隱藏效果
- jQuery實現(xiàn)鼠標(biāo)經(jīng)過時出現(xiàn)隱藏層文字鏈接的方法
- jQuery響應(yīng)鼠標(biāo)事件并隱藏與顯示input默認(rèn)值
- jQuery 網(wǎng)易相冊鼠標(biāo)移動顯示隱藏效果實現(xiàn)代碼
- 基于JQuery實現(xiàn)鼠標(biāo)點擊文本框顯示隱藏提示文本
- 基于jquery鼠標(biāo)點擊其它地方隱藏層的實例代碼
- jQuery實現(xiàn)表單input中提示文字value隨鼠標(biāo)焦點移進(jìn)移出而顯示或隱藏的代碼
- jquery插件實現(xiàn)鼠標(biāo)隱藏
相關(guān)文章
很棒的學(xué)習(xí)jQuery的12個網(wǎng)站推薦
jQuery是目前最流行的 JavaScript 庫。對于初學(xué)者來說,有的時候很難找到一個好的學(xué)習(xí)jQuery的網(wǎng)站,今天本文收集了12個很棒的 jQuery 學(xué)習(xí)網(wǎng)站推薦給大家。2011-04-04關(guān)于jquery中動態(tài)增加select,事件無效的快速解決方法
下面小編就為大家?guī)硪黄P(guān)于jquery中動態(tài)增加select,事件無效的快速解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-08-08淺析LigerUi開發(fā)中謹(jǐn)慎載入common.css文件
這一句是載頁面載入時,顯示正在載入動畫效果,但是極大影響了程序開發(fā)里的調(diào)試。給新手的建議,希望可以參考下2013-07-07