jQuery實現(xiàn)點擊行選中或取消CheckBox的方法
642
2024-02-23
本文實例分析了jQuery遮罩層實現(xiàn)方法。分享給大家供大家參考,具體如下:
1 背景半透明遮罩層樣式
需要一個黑色(當然也可以其他)背景,且須設(shè)置為絕對定位,以下是項目中用到的css樣式:
/* 半透明的遮罩層 */ #overlay { background: #000; filter: alpha(opacity=50); /* IE的透明度 */ opacity: 0.5; /* 透明度 */ display: none; position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; z-index: 100; /* 此處的圖層要大于頁面 */ display:none; }
2 jQuery實現(xiàn)遮罩
/* 顯示遮罩層 */ function showOverlay() { $("#overlay").height(pageHeight()); $("#overlay").width(pageWidth()); // fadeTo第一個參數(shù)為速度,第二個為透明度 // 多重方式控制透明度,保證兼容性,但也帶來修改麻煩的問題 $("#overlay").fadeTo(200, 0.5); } /* 隱藏覆蓋層 */ function hideOverlay() { $("#overlay").fadeOut(200); } /* 當前頁面高度 */ function pageHeight() { return document.body.scrollHeight; } /* 當前頁面寬度 */ function pageWidth() { return document.body.scrollWidth; }
3 提示框
遮罩的目的無非讓人無法操作內(nèi)容,突出提示框,而提示框可參考上面的制作,z-index比遮罩層更高便可。主要問題是,如何控制提示框在瀏覽器居中。
/* 定位到頁面中心 */ function adjust(id) { var w = $(id).width(); var h = $(id).height(); var t = scrollY() + (windowHeight()/2) - (h/2); if(t < 0) t = 0; var l = scrollX() + (windowWidth()/2) - (w/2); if(l < 0) l = 0; $(id).css({left: l+'px', top: t+'px'}); } //瀏覽器視口的高度 function windowHeight() { var de = document.documentElement; return self.innerHeight || (de && de.clientHeight) || document.body.clientHeight; } //瀏覽器視口的寬度 function windowWidth() { var de = document.documentElement; return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth } /* 瀏覽器垂直滾動位置 */ function scrollY() { var de = document.documentElement; return self.pageYOffset || (de && de.scrollTop) || document.body.scrollTop; } /* 瀏覽器水平滾動位置 */ function scrollX() { var de = document.documentElement; return self.pageXOffset || (de && de.scrollLeft) || document.body.scrollLeft; }
補充:
jQuery簡單遮罩層插件:
jQuery代碼:
(function ($) { $.fn.ShowMask = function (options) { var defaults = { top: 150, left: 200 } var options = $.extend(defaults, options); $("html").append('<div id="ui-mask"></div><div id="ui-mask-div" style="z-index: 99999;position: fixed;top:' + options.top + 'px;left:' + options.left + 'px;"><img src="http://www.gimoo.net/t/1904/Images/ui-loading.gif" alt="" /><span>操作正在進行中,請耐心等待......</span></div>') _this_ = $("#ui-mask"); _this_.height($(document).height()) _this_.show(); }; $.fn.HideMask = function (options) { _this_ = $("#ui-mask"); _this_.remove(); }; })(jQuery);
css樣式:
#ui-mask { background-color: #666; position: absolute; z-index: 9999; left: 0; top: 0; display: none; width: 100%; height: 100%; opacity: 0.5; filter: alpha(opacity=50); -moz-opacity: 0.5; } #ui-mask-div img { width: 50px; height: 50px; float: left; } #ui-mask-div span { height: 50px; line-height: 50px; display: block; float: left; color: Red; font-weight: bold; margin-left: 5px; }
使用方法:
function btn_save() { $(this).ShowMask(); $.post('url',null,function(d,s){ $(this).HideMask(); }); }
希望本文所述對大家jQuery程序設(shè)計有所幫助。
#免責聲明#
本站[綠夏技術(shù)導航]提供的一切軟件、教程和內(nèi)容信息僅限用于學習和研究目的;不得將上述內(nèi)容用于商業(yè)或者非法用途,否則,一切后果請用戶自負。本站信息來自網(wǎng)絡(luò)收集整理,版權(quán)爭議與本站無關(guān)。您必須在下載后的24個小時之內(nèi),從您的電腦或手機中徹底刪除上述內(nèi)容。如果您喜歡該程序或內(nèi)容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權(quán)問題,如有侵權(quán)請郵件[admin@lxwl520.com]與我們聯(lián)系進行刪除處理。敬請諒解!