[英]How to add an overlay to body when button clicked, and how to clear purplecoat content on pageload
I have two issues/questions... 我有两个问题/问题...
Question #1: I am using a label overlay plugin called purplecoat.js ( http://ellekasai.github.io/purplecoat.js/ ) and I need to find a way to add an overlay backdrop to the entire body when the "toggle hints" button is clicked. 问题1:我使用的标签叠加插件名为Purplecoat.js( http://ellekasai.github.io/purplecoat.js/ ),当“单击切换提示”按钮。 Right now, when the toggle hints button is clicked, it displays the labeled overlays over the identified content, but I also want a complete background overlay added to the body to help bring focus to the labeled overlays. 现在,单击切换提示按钮时,它会在已标识的内容上显示标记的叠加层,但是我也希望将完整的背景叠加层添加到正文中,以帮助将焦点对准标记的叠加层。
My 2nd issue is, my actual website is a multi-page site and I need to use this purplecoat overlay plugin on each page so users can click to see the labeled hints. 我的第二个问题是,我的实际网站是一个多页网站,我需要在每页上使用这个Purplecoat覆盖插件,以便用户可以单击以查看带标签的提示。 My problem is when the user clicks on the Toggle Hints button to view the labeled hints on one page, it will work fine, but when they open a new page of the site and click on the same toggle hints button, it shows the labeled hints from the previous page. 我的问题是,当用户单击“切换提示”按钮在一页上查看带标签的提示时,它会正常工作,但是当他们打开网站的新页面并单击相同的切换提示按钮时,它会显示带标签的提示从上一页开始。 If I refresh the page, then it shows the correct updated hints. 如果刷新页面,则显示正确的更新提示。
I need to find a way to clear the purplecoat.js content when a new page loads, so it does not show the wrong label overlays - or somehow discretely refresh the page when someone opens a new page so it clears the purplecoat.js. 我需要找到一种方法来在加载新页面时清除purplecoat.js内容,以便它不会显示错误的标签覆盖-或以某种方式在有人打开新页面时以离散方式刷新页面以清除purplecoat.js。
I have a jsfiddle of my login page where the purplecoat.js label overlay is working when clicking on the Toggle Hints link. 我的登录页面有一个jsfiddle,单击“切换提示”链接时,purplecoat.js标签覆盖层起作用。 I just need to add the backdrop overlay, then clear the purplecoat.js when a new page/or modal is loaded. 我只需要添加背景图叠加层,然后在加载新页面/模式时清除purplecoat.js。 My site has several pages and modals, and the pages and modals are all opened with a button - so if there is a way to clear the purplecoat.js cache when any button is clicked, may work. 我的网站有多个页面和模态,并且页面和模态都用一个按钮打开-因此,如果有一种方法可以在单击任何按钮时清除Purplecoat.js缓存,则可能会起作用。 I am open to suggestions. 我愿意提出建议。
JSFiddle link: https://jsfiddle.net/txptbf15/ JSFiddle链接: https ://jsfiddle.net/txptbf15/
I am new to learning jQuery/js, so please be kind! 我刚开始学习jQuery / js,所以请客气! :-) :-)
HTML (of my login page): HTML(我的登录页面):
<div id="hints"><button data-purplecoat-toggle="foo" class="btn-loginHint">Toggle Hints!</button></div>
<div id="Login" class="loginTemplate panel panel-primary">
<div class="panel-heading clearfix">
<h2 class="pull-left">Log On</h2>
<div id="LangWrapper" class="pull-right">
<button id="LangButton" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" data-purplecoat="foo" data-purplecoat-label="Select Language" data-purplecoat-color="rgba(238, 122, 39, 0.9)">
<span id="chooseLanguage">Language</span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li onclick="_.utils.ChangeLanguage('en')"><a href="#">(English)</a></li>
<li onclick="_.utils.ChangeLanguage('jp')"><a href="#">(日本語)</a></li>
</ul>
</div>
</div>
<div class="panel-body">
<p>Please enter your username and password</p>
<form class="">
<fieldset class="">
<legend>Account Info</legend>
<div class="form-group">
<label for="accountType">Account Type</label>
<select class="form-control" id="accountType" name="accountType" data-purplecoat="foo" data-purplecoat-label="Select Account from menu that you want to access." data-purplecoat-color="rgba(238, 122, 39, 0.9)">
<option value="customer">Option 1</option>
<option value="reseller">Option 2</option>
</select>
</div>
<div class="form-group">
<label for="email">EMail</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Email" data-purplecoat="foo" data-purplecoat-label="Input email address you used when registering." data-purplecoat-color="rgba(238, 122, 39, 0.9)">
</div>
<div class="form-group">
<label for="email">Password</label>
<input type="password" class="form-control" id="pwd" name="pwd" placeholder="Password" data-purplecoat="foo" data-purplecoat-label="Input password you used when registering." data-purplecoat-color="rgba(238, 122, 39, 0.9)">
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" class="checkbox" name="RememberMe" value="1" /> Keem me logged in
</label>
</div>
</div>
<p class="actions">
<button type="button" id="btnSubmit" class="btn btn-primary" data-purplecoat="foo" data-purplecoat-label="Select button to Login" data-purplecoat-color="rgba(238, 122, 39, 0.9)"><i class="fa fa-sign-in"></i> Log In</button>
<a href="#" id="ForgotPasswordLink" class="btn btn-default" data-purplecoat="foo" data-purplecoat-label="Select button to retrieve password." data-purplecoat-color="rgba(238, 122, 39, 0.9)"><i class="fa fa-puzzle-piece"></i> Forgot Password</a>
<a id="loginRegister" href="#"
class="pull-right" data-purplecoat="foo" data-purplecoat-label="Select to Register" data-purplecoat-color="rgba(238, 122, 39, 0.9)"><i class="fa fa-key"></i> Register</a>
</p>
</fieldset>
</form>
</div>
</div>
CSS: CSS:
.purplecoat { display: none; position: absolute; padding: 5px; box-sizing: border-box; background-color: rgba(142, 68, 173, 0.9); color: #FFF; text-align: center; font-weight: bold; overflow: hidden; z-index: 9999; } .purplecoat-inner { display: table; width: 100%; height: 100%; } .purplecoat-inner-text { display: table-cell; vertical-align: middle;}
.purplecoat {
padding: 0 !important;
font-size: 12px !important;
line-height: 1.2em !important;
}
.btn-loginHint {
background-color: transparent;
color: #fff;
border: none;
float: left;
padding-top: 5px;
}
Regarding Problem 1: the issue seems to be with z-index
on all the purplecoat divs; 关于问题1:问题似乎与所有Purplecoat div的z-index
有关; it's set to 9999. As a result what you need is an overlay div with a higher z-index. 它将其设置为9999。因此,您需要的是一个具有较高z-index的叠加层div。 See my sample below. 请参阅下面的示例。 I've also added a div with the id of overlay. 我还添加了一个带有叠加ID的div。 Here is my working fiddle. 这是我的工作小提琴。
#overlay {
display:none;
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
width:100%
height:100%;
background-color:white;
z-index:10000;
}
Regarding Problem 2: I'm not sure how you're loading the pages, but this worked in my fiddle. 关于问题2:我不确定您如何加载页面,但这在我的小提琴中起作用。
$('[data-purplecoat-for]').hide();
After looking at the source code it seems all those overlays have the same property data-purplecoat-for
, simply calling hide on them will work. 在查看源代码之后,似乎所有这些叠加层都具有相同的属性data-purplecoat-for
,只需在其上调用hide即可。 Again if this doesn't work for you I need a little more info. 同样,如果这对您不起作用,我需要更多信息。 By the way, the github project says it's no longer being maintained. 顺便说一下,github项目说它不再被维护。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.