The JS & jquery masking layer implements mouse events that prohibit elements such as a, span, button, and so on

Source: Internet
Author: User
<span id="Label3"></p><p><p>Just writing an interface, in order to consider the background picture, so the use of a button instead of a tag</p></p><p><p>You should disable the A element after clicking, it is easier to disable the button, plus a disabled.</p></p><p><p>But for a but there is no good way, always can not put href= "", not to mention I was walking the onclick function</p></p><p><p>So Baidu a bit, and then see a useful mask implementation, the source code has a bug, and then follow its own ideas to rewrite a bit</p></p><p><p>---------</p></p><p><p>Stick to the code below, this mask layer implementation is actually a layer outside the current element wrap, a layer of a z-index larger transparent layer, directly covering the original elements</p></p><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><pre><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">1</span></span> <span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 128, 0);">/*</span></span><span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 128, 0);">Mask Layer Code</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">2</span></span> <span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 128, 0);">role: prevent too many forms from being submitted by masking layers</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">3</span></span> <span style="color: rgb(0, 128, 0);"><span style="color: rgb(0, 128, 0);">*/</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">4</span></span> <span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">function</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Maskit (obj) {</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">5</span></span> <span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">var</span></span>Hoverdiv = ' <div class= "divmask" style= "position:absolute; width:100%; height:100%; left:0px; top:0px; Background: #fff; opacity:0; Filter:alpha (opacity=0); z-index:5; " ></div> '<span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">;</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">6</span></span>$ (obj). Wrap (' <div class= "position:relative;" ></div> '<span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">);</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">7</span></span> <span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">$ (obj). before (hoverdiv);</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">8</span></span>$ (obj). Data ("mask",<span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">true</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">);</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">9</span></span> <span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">}</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);">Ten</span></span> <span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">function</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Unmaskit (obj) {</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> one</span> <span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">if</span></span>($ (obj). Data ("mask") = =<span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">true</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">){</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> a</span>$ (obj). Parent (). Find (". divmask"<span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">). Remove ();</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> -</span> <span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">$ (obj). Unwrap ();</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> -</span>$ (obj). Data ("mask",<span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">false</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">);</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> the</span> <span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"> }</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> -</span>$ (obj). Data ("mask",<span style="color: rgb(0, 0, 255);"><span style="color: rgb(0, 0, 255);">false</span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">);</span></span><span style="color: rgb(0, 128, 128);"><span style="color: rgb(0, 128, 128);"></span> -</span>}</pre><span class="cnblogs_code_copy"><span class="cnblogs_code_copy"></span></span><p><p>The call method is very simple, for example, now there is a <a id= "test1" > Point me </a></p></p><p><p>directly, you can:</p></p><p><p>Maskit ($ (' #test1 '));</p></p><p><p>You can add a mask, and the hood is the Same.</p></p><p><p>    </p></p><p><p>That's All.</p></p></span>

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.