Open external link as an overlay on the same page - javascript

I got a little slider with a black background with
opacity: 0.6
This is an external index.html (with a CSS, JS and img folder).
I'd like to open that index.html when i hit a link on an external page. So the page is just covered with that black overlay and the slider.
Do I have to do this with an iframe, which fades in? So like:
$(document).ready(function () {
$('#mylink a').click(function(){
var iframeSrc = $(this).attr('href');
$('#myiFrame').fadeOut(1000,function(){
$('#myiFrame iframe').attr('src',iframeSrc);
$('#myiFrame').fadeIn(1000);
});
return false;
});
});
Or is there any easier solution? The little problem is that I have to be able to write the text in a HTML-editor only, because where I got that link to open the slider is in a CMS with a HTML-Editor.

If I got u correctly-
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
body {
margin: 0;
font-family: 'Lato', sans-serif;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
<div id="myNav" class="overlay">
×
<div class="overlay-content">
<iframe src="http://www.w3schools.com/"></iframe>
</div>
</div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>

Related

I'm trying to move a <span> for an animated menu inside of a <div> down, but it stays put, overlaying content in another div

Thats not all... when I inspect through chrome for iPhone X it appears correctly and so for desktop as well. I'm using dreamweaver and when I choose to view directly from my device is where I see the problem. Image is directly from mobile device. Also wanting to move it a little out the corner, but nothing. Please help! [1]: https://i.stack.imgur.com/pzbyL.jpg
.sidenav {
height:50%;
width: 0%;
position: absolute;
z-index: 1;
bottom: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
transition: 0.5s;
padding-top: 40px;
}
.sidenav a {
padding: 50px 8px 8px 60px;
text-decoration: none;
font-size: 25px;
color: #818181;
display: block;
transition: 0.3s;
}
.sidenav a:hover {
color: #f1f1f1;
}
.sidenav .closebtn {
position: absolute;
bottom: 0;
right: 25px;
font-size: 36px;
margin-left: 50px;
}
#button .span{
margin:auto;
padding-top: 2em;
padding-bottom: 5em;
left:0;
}
<div id="button">
<span style="font-size:30px;cursor:pointer" onclick="openNav()">menu</span>
</div>
<div id="mySidenav" class="sidenav">
×
About
Book
Portfolio
</div>
<script>
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>

Open close sidebar clicking anywhere

I need to create a sidebar that can be able to close it clicking on the X button and clicking anywhere
I am able to close the navbar by clicking on the X button in the sidebar. How can I change my javascript to be able to close the sidebar by clicking anywhere on the page?
function openNav() {
document.getElementById('mySidenav').style.width="250px";
}
function closeNav() {
document.getElementById('mySidenav').style.width="0"
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
background-color: #111;
}
.sidenav a{
display: block;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
transition: 0.3s;
}
.sidenav a:hover{
color: #F1F1F1;
}
.sidenav .closebtn{
position: absolute;
top: 0;
right: 25px;
font-size: 35px;
margin-left: 50px;
}
#media screen and (max-height: 450px){
.sidenav{padding-top: 15px;}
.sidenav a{font-size: 18px;}
}
<body>
<div id="mySidenav" class="sidenav">
×
CARRITO 1
CARRITO 2
</div>
<h2>Animated Sidenav</h2>
<p>Click on the element below to open sidenav</p>
<span style="cursor: pointer;" onclick="openNav()">cart</span>
</body>
You can listen to clicks on your entire page through:
document.body.onclick = function () {
// Close Nav here
}
However, doing this will cause your entire page to try to close the nav when clicked – even your open button.
You can exclude certain elements from listening to events set on parent elements through the e.stopPropagation() method. See an example implementation below.
Please also note that your body will not start off 100% of your window's height due to the lack of content, and thus will not respond to clicks everywhere on the page. You can fix this by using setting the CSS property body: 100vh.
function openNav(e) {
e.stopPropagation();
document.getElementById('mySidenav').style.width="250px";
}
function closeNav(e) {
e.stopPropagation();
document.getElementById('mySidenav').style.width="0"
}
document.body.onclick = closeNav;
document.getElementsByClassName('openbtn')[0].onclick = openNav;
document.getElementById('mySidenav').onclick = openNav;
document.getElementsByClassName('closebtn')[0].onclick = closeNav;
body {
height: 100vh;
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
right: 0;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
background-color: #111;
}
.sidenav a {
display: block;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
transition: 0.3s;
}
.sidenav a:hover {
color: #F1F1F1;
}
.sidenav .closebtn {
position: absolute;
top: 0;
right: 25px;
font-size: 35px;
margin-left: 50px;
}
#media screen and (max-height: 450px) {
.sidenav{padding-top: 15px;}
.sidenav a{font-size: 18px;}
}
<body>
<div id="mySidenav" class="sidenav">
×
CARRITO 1
CARRITO 2
</div>
<h2>Animated Sidenav</h2>
<p>Click on the element below to open sidenav</p>
<span style="cursor: pointer;" class="openbtn">cart</span>
</body>
Easily you can add overlay element when the sidebar is shown.
function overlay(isShow){
var elm = document.getElementById('overlay')
if (isShow) {
elm.style.display = 'block';
} else {
elm.style.display = 'none';
}
}
function openNav() {
overlay(true);
document.getElementById('mySidenav').style.width="250px";
}
function closeNav() {
overlay(false);
document.getElementById('mySidenav').style.width="0"
}
.sidenav {
height: 100%;
width: 0;
position: fixed;
z-index: 3;
top: 0;
right: 0;
overflow-x: hidden;
transition: 0.5s;
padding-top: 60px;
background-color: #111;
}
.sidenav a{
display: block;
padding: 8px 8px 8px 32px;
text-decoration: none;
font-size: 25px;
color: #818181;
transition: 0.3s;
}
.sidenav a:hover{
color: #F1F1F1;
}
.sidenav .closebtn{
position: absolute;
top: 0;
right: 25px;
font-size: 35px;
margin-left: 50px;
}
#overlay{
z-index: 2;
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
display: none;
}
#media screen and (max-height: 450px){
.sidenav{padding-top: 15px;}
.sidenav a{font-size: 18px;}
}
<div id="mySidenav" class="sidenav">
×
CARRITO 1
CARRITO 2
</div>
<h2>Animated Sidenav</h2>
<p>Click on the element below to open sidenav</p>
<span style="cursor: pointer;" onclick="openNav()">cart</span>
<div id="overlay" onclick="closeNav()"></div>

Is it possible for contents in a nav bar to act as buttons not links

I am trying to keep my buttons concise inside a menu nav bar but I noticed most of the contents in the nav bar act as links, I want to store table in my buttons, inside the nav bar. I don't know if this is possible or sensible. I am really new at this..............................................................
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'Lato', sans-serif;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
</style>
</head>
<body>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×
</a>
<div class="overlay-content">
About
Services
Clients
Contact
</div>
</div>
<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:
</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
function openNav() {
document.getElementById("myNav").style.width = "50%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</body>
</html>
This should give you what you need. Change your menu links to
<div class="overlay-content">
<button class="buttonStyle" href="#">About</button>
<button class="buttonStyle" href="#">Services</button>
<button class="buttonStyle" href="#">Clients</button>
<button class="buttonStyle" href="#">Contact</button>
</div>
Then add the following to your style.
.buttonStyle {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
background-color: transparent;
border: 0;
outline: 0;
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.buttonStyle:hover {
color: #f1f1f1;
}
All we've done here is changed your <a> tags to <button> tags and styled your button so it appears the same as your text links. Hope this helps.
Edit: You will need to edit your media query to add responsiveness again :)
<style>
body {
font-family: 'Lato', sans-serif;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
.buttonStyle {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
background-color: transparent;
border: 0;
outline: 0;
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.buttonStyle:hover {
color: #f1f1f1;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
</style>
<body>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×
</a>
<div class="overlay-content">
About
<button class="buttonStyle" href="#">Services</button>
<button class="buttonStyle" href="#">Clients</button>
<button class="buttonStyle" href="#">Contact</button>
</div>
</div>
<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:
</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
function openNav() {
document.getElementById("myNav").style.width = "50%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</body>
Add .btn class to your link and add some styles. With :active selector, you can add click effect like standard button - for example: inset shadow.
.overlay a.btn {
background: #818181;
color: #fff;
display: inline-block;
font-weight: 600;
font-size: 36px;
line-height: 36px;
text-align: center;
vertical-align: middle;
cursor: pointer;
border-radius: 6px;
padding: 17px;
text-transform: uppercase;
text-decoration: none;
white-space: normal;
}
.overlay a.btn:active {
box-shadow: inset 0px 0px 8px rgba(0,0,0,.7);
}
About
See, here I've the working snippet, you can change color and padding /margin for button class according to you.
function openNav() {
document.getElementById("myNav").style.width = "50%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
.button {
display: block;
width: 115px;
height: 25px;
padding: 10px;
text-align: center;
border-radius: 5px;
color: white;
font-weight: bold;
margin-left : 100px;
margin-bottom:5px;
}
body {
font-family: 'Lato', sans-serif;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
<!DOCTYPE html>
<div id="myNav" class="overlay">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×
</a>
<div class="overlay-content">
About
Services
Clients
Contact
</div>
</div>
<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:
</p>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
You could do like this if you wan't to keep your links for some reason:
<!DOCTYPE>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
</head>
<body>
alikn
</body>
</html>
<script>
function hRefClick(event){
event.preventDefault();
alert("redirection prevented");
}
</script>

Full screen menu only appears in nav bar

I have got the following html and css. The problem is when it is run the full screen menu only appears in the nav bar. The problem only appears when using safari.
I can solve the problem my getting rid of
.nav {
position: fixed;
}
but I still want the nav bar to be fixed at the top of the page.
.nav {
font-family: Arial-BoldMT;
font-size: 16px;
list-style: none;
text-align: right;
padding: 0px 0 0px 0;
box-shadow:0px 1px 1px #d3d3d3;
background-color: white;
width: 100%;
z-index:0.1;
overflow: auto;
position: fixed;
top: 0;
}
.nav p {
float: left;
margin-left: 40px;
color: #333333;
}
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
.slider {
font-size:30px;
cursor:pointer;
float:right;
margin-right: 40px;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
<div class="nav">
<p>LIAM VINSON</p>
<div id="myNav" class="overlay">
×
<div class="overlay-content">
HOME
ABOUT
PHOTOGRAPHY
PORTFOLIO
CONTACT
</div>
</div>
<span class="slider" onclick="openNav()">☰</span>
<script>
function openNav() {
document.getElementById("myNav").style.width = "100%";
}
function closeNav() {
document.getElementById("myNav").style.width = "0%";
}
</script>
</div>
z-index:0.1;
is not valid css.
z-index must be an integer - either negative or positive. Chances are most browsers are just treating it as 0, but Safari don't know what to do with it. So, change it to an integer like
z-index:1;
and set your overlay to z-index:2 (though I would recommend spacing these numbers out in case you have to index additional elements. ie. z-index:100; and z-index:200;)
Setting it as fixed, with top at 0, should fix it to the top of page for you once you correct that z-index issue you got there.
The problem was
.nav {
overflow: auto;
}
It stopped the overlay from being shown outside of the nav div.

Overlay with auto display on page load

I have been trying for days to get this to work, I am looking to have this overlay as is but simply initiate on page load instead of having to click the link in order to have it open. Can anyone suggest what i can do to have it auto overlay when someone visits?
<!DOCTYPE html>
<html>
<style>
body {
margin: 0;
font-family: 'Lato', sans-serif;
}
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.6);
overflow-y: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay {overflow-y: auto;}
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
</style>
<body>
<div id="myNav" class="overlay">
×
<div class="overlay-content">
About
Services
Clients
Contact
</div>
</div>
<h2></h2>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
function openNav() {
document.getElementById("myNav").style.height = "100%";
}
function closeNav() {
document.getElementById("myNav").style.height = "0%";
}
</script>
</body>
</html>
Just add document.addEventListener('DOMContentLoaded', openNav()); inside your <script>
Shorthand : document.ready(openNav());
For more information check out: js document.ready()
add openNav()
openNav()
<!DOCTYPE html>
<html>
<style>
body {
margin: 0;
font-family: 'Lato', sans-serif;
}
.overlay {
height: 0%;
width: 100%;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.6);
overflow-y: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay {overflow-y: auto;}
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
</style>
<body>
<div id="myNav" class="overlay">
×
<div class="overlay-content">
About
Services
Clients
Contact
</div>
</div>
<h2></h2>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ open</span>
<script>
function openNav() {
document.getElementById("myNav").style.height = "100%";
}
function closeNav() {
document.getElementById("myNav").style.height = "0%";
}
</script>
</body>
</html>

Categories

Resources