jquery masking Layer Plug-in

Source: Internet
Author: User

On the Web page often encounter the need to wait very long operations, such as export reports. To prevent users from clicking on other actions or clicking the same function multiple times, cover the page or the operating area with a mask layer. Prevent the user from doing the next step. At the same time, it can improve the interface friendliness, let the user know that the operation is running.

$.fn.extend ({/** * adds mask layer to element * @param message {String} [optional] mask layer display content */mask:function (message) {var $target = this,fixed = False,targetstatic = True;if (Object.prototype.toString.call (message)!== ' [Object String] ' | |!message) {// Assuming that the message is empty or not a string, use the default message hint.

Message = ' Please wait.

。。 ‘;} if ($target. length = = 0) {$target = $ (' body '),} else {if ($target. length > 1) {$target = $target. First ();} if ($target [0] = = = Window | | $target [0] = = = document) {$target = $ (' body ');}} if ($target [0] = = = document.body) {fixed = true;} Assuming that the target element already has a mask layer, get the matte layer var old = $target. Data (' Rhui.mask '), if (old) {old. $content. HTML (message); Center ($target, old.$ content, fixed); return;} Assume that the masked element is static. Change the element to Relativeif ($target. css (' position ') = = = ' static ') {targetstatic = true; $target. css (' position ', ' relative ');} var $content, $overlay; if (fixed) {$overlay = $ (' <div class= "Rhui-mask" style= "position:fixed;" ></div> '); $content = $ (' <div class= "rhui-mask-content" style= "position:fixed;" > ' + message + ' </div> ');} else {$overlay = $ (' <div class= "Rhui-mask" ></div> ") $content = $ (' <div class= ' rhui-mask-content" > ' + Message + ' </div> ');} $overlay. AppendTo ($target); $content. AppendTo ($target);//Display Mask layer $overlay.show (); $content. Show ();//Let the Matte Layer Center Center ($ Target, $content, fixed);//Add mask layer information to $target$target.data (' Rhui.mask ', {fixed:fixed, $overlay: $overlay, $content: $content, Targetstatic:targetstatic});/** * Let the mask layer content be centered * @param $target obscured element * @param $content Mask Layer content element * @param fixed cover Whether the cover layer is fixed display */function Center ($target, $content, fixed) {var $window, height = $content. Outerheight (True), Width = $ Content.outerwidth (True); if (fixed) {//assumes that the matte layer is fixed display. Let the Mask Layer Center in the window $window = $ (window), $content. css ({left: ($window. Width ()-width)/2,top: ($window. Height ()-height)/2}); } else {//Let mask layer be centered in $target $content.css ({left: ($target. Width ()-width)/2,top: ($target. Height ()-height)/2});}}},/** * Remove Mask Layer */unmask:function () {var $target; if (this.length = = = 0) {$target = $ (' body '),} else {$target = This.first (); if ( $target [0] = = = Window | | $target [0] = = = document) {$target = $ (' body ');}} var data = $target. Data (' Rhui.mask '); if (!data) {return;} Restore the Position property of the target element if (data.targetstatic) {$target. css (' position ', ' static ');} Data. $overlay. Remove ();d ATA. $content. remove (); $target. Removedata (' Rhui.mask ');}});


Plug-in styles are controlled by the Rhui-mask and Rhui-mask-content classes, Rhui-mask is the mask layer style, and rhui-mask-content is the hint content style of the matte layer.

/* Mask layer style */.rhui-mask {Position:absolute;top:0;right:0;bottom:0;left:0;z-index:9000;display:block;margin:0;paddin G:0;border-style:none;background-color: #777; Opacity:0.3;zoom:1;filter:alpha (opacity=30);} /* Mask layer display content style */.rhui-mask-content {position:absolute;z-index:9999;display:block;margin:0;padding:15px 20px;border: 2PX solid RGB (109, 157, 215); Background-color: #fff; color:blue;letter-spacing:2px;font-weight:bold;font-size:15px; cursor:wait;}

Effect of what you see


Page Call complete code

<! DOCTYPE html>

。 ‘);}); </script></body>


jquery masking Layer Plug-in

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.