简体   繁体   English

如何在我的所有网页上显示叠加层?

[英]How can I have an overlay appear on all of my web pages?

I'm setting up a website and I would like the ability for a user to press a button to open an overlay (code is below), which would appear on every web page. 我正在建立一个网站,我希望用户能够按下按钮打开覆盖图(代码在下面),这将显示在每个网页上。

I have already tried going through each individual file, pasting the code but it is becoming tedious, due to the number of files that i have and a number of file conflicts. 我已经尝试浏览每个单独的文件,粘贴代码但由于我拥有的文件数量和一些文件冲突而变得乏味。

<style>
#overlay {
  position: fixed;
  display: none;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0,0,0,1);
  z-index: 2;
  cursor: pointer;
}

#text{
  position: absolute;
  top: 50%;
  left: 50%;
  font-size: 50px;
  color: white;
  transform: translate(-50%,-50%);
  -ms-transform: translate(-50%,-50%);
}
</style>
</head>
<body>

<div id="overlay" onclick="off()">
  <div id="text">Overlay Text</div>
</div>

<div style="padding:20px">
  <button onclick="on()">Hide</button>
</div>

<script>
function on() {
  document.getElementById("overlay").style.display = "block";
}

function off() {
  document.getElementById("overlay").style.display = "none";
}
</script>

unless you have the ability to use includes or fragments, you either have to include a div on every page OR you could use jquery html to insert via a global js file. 除非您能够使用包含或片段,否则您必须在每个页面上包含div,或者您可以使用jquery html通过全局js文件插入。

something like this inside your click event: 在你的点击事件中有类似的东西:

 $( ".btn" ).on( "click", function() { $('#overlay').html("<div id="overlay"><div id="text">Overlay Text</div></div>"); }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Github Pages 上托管我的 javascript web 应用程序? - How can I host my javascript web application on Github Pages? 如何在我的所有网页中显示用户名...? - how to display the username in all my web pages…? 如何在我的网站上的所有页面上进行搜索 - How can I search across all pages on my website 如何在我的 JSF web 应用程序中拥有 AJAX 功能? - How can I have AJAX functionality in my JSF web application? 在执行我的JavaScript之前,如何等待网页加载完毕并填充所有控件? - How can I wait until a web page has loaded and all controls have been populated before executing my javascript? 我怎样才能在 axios 的反应中让我的每个测验问题及其在不同页面中的选择 - How can I have each of my my quiz questions and their choices in different pages in react by axios 为什么两个网页有不同的localStorage?我怎样才能解决这个问题? - Why do two web pages have different localStorage? How can I fix this? 我如何有一个搜索框,人们可以在其中搜索我站点内的页面? - How can I have a search box where people can search for pages within my site? 如何让输出显示在一行中没有空格? - How can I make my output appear all on one line with no spaces? 我如何在其余所有页面中具有第一页的相同页眉 - How can i have same header of first page in rest of all the pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM