Using native JS to implement page masking (mask) effect sample code _javascript Tips

Source: Internet
Author: User

For Web application developers, users can wait longer on a Web page if the daemon processes a long time while the user is browsing the interface, but if there is no friendly hint on the page

(Add the gray effect), then the user experience will not be particularly good, users do not know whether to click another program now, users do not know whether should continue to wait for the page, or can click on another page.

Now there is a better interaction, is to increase the effect of the gray. The Mask () and unmask () features of JS-like frameworks provide a extjs effect, and jquery, of course, provides this method of Monte-ash. The author hopes that he can also

Use the native JS to achieve your own masking effect. So I made a try. To achieve the effect of the ash mask. In this I only focus on implementation, the page beautiful degree I do not have too many adjustments, so the page is not very beautiful. The implementation code is posted here.

View a code slice from my Code chip

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New Document &L t;/title> <meta name= "generator" content= "EditPlus" > <meta name= "Author" content= "" > <meta NAME= "Key Words "content=" "> <meta name=" Description "content=" "> <style type=" text/css "> Maskstyle" background 
-color: #B8B8B8; 
Z-index:1; 
Filter:alpha (OPACITY=50); 
opacity:0.8; 
Position:absolute; 
Text-align:center; 
Color:blue; 
Font:bold 1em "Song Body", Arial,times; 
height:25px; 
Font-weight:bold; 

Overflow:hidden; } </style> </HEAD> <script type= "Text/javascript" > Function Creatmasklayer (effectitem,showtext) {D 
Ivitem = document.createelement ("div"); 
Divitem.classname= "Maskstyle"; 
divitem.style.lineheight=effectitem.offsetheight+ "px"; 
Divitem.innertext=showtext; 
Divitem.style.width=effectitem.offsetwidth; 
Divitem.style.height=effectitem.offsetheight; 
Divitem.style.top=effectitem.offsettop; Divitem.Style.left=effectitem.offsetleft; 
return divitem; 
function Setmask () {var effectitem = document.getElementById ("test"); 
var Existmaskitem = Findmaskitem (Effectitem); 
if (Existmaskitem) {return; 
var showtext = "Load ..."; 
Effectitem.appendchild (Creatmasklayer (Effectitem,showtext)); 
function Removemask () {var effectitem = document.getElementById ("test"); 
var Maskitem = Findmaskitem (Effectitem); 
if (Maskitem) {effectitem.removechild (Maskitem); 
} function Findmaskitem (item) {var children = Item.children; 
for (Var i=0;i<children.length;i++) {if ("maskstyle" = = (Children[i].classname)) {return children[i]; }} </script> <BODY> <input type= "button" value= "Gray" onclick= "Setmask ()"/> <input type= "Butto N "value=" suppresses onclick= removemask () "/> <br> <div id=" test "style=" border:1px : 300px "> <input type=" button "value=" test if you can also click "onclick=" alert (' ok! ') /> </div> </BODY> &Lt;/html> 


Explain the more important parts of the code.

. Maskstyle is the style of a gray layer

which
View a code slice from my Code chip

Filter:alpha (OPACITY=50); 

Represents the opacity layer transparency, the Filter property is intended to be compatible with the IE8 browser

The Z-index property sets the stacking order of the elements. Elements that have a higher stacking order are always in front of elements that have a lower stacking order.

PS: The gray effect needs to be gray to the element into the div can be

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.