Michael Raysh
Michael Raysh

Reputation: 3

How do I keep an overlay open by default with Javascript?

Hey guys I have a login overlay with the following code:

<!-- The overlay -->
<div id="myNav" class="overlay">

<!-- Login goes here -->

<!-- End login -->
</div>

<!-- Use any element to open/show the overlay navigation menu -->
<span onclick="openNav()">open</span>

I'm using Javascript to open it, and removed the close button.

<script type="text/javascript">

function openNav() {
    document.getElementById("myNav").style.width = "100%";
}

/* Close when someone clicks on the "x" symbol inside the overlay */
function closeNav() {
    document.getElementById("myNav").style.width = "0%";
}

</script>

My question is how do I keep the default set to open? Thank you in advance.

Upvotes: 0

Views: 223

Answers (1)

WilomGfx
WilomGfx

Reputation: 2013

Well if i understand the problem.... and how your CSS is setup...

With just some good old CSS

#myNav {
 width:100%;
}

That way its always 100% with when the page loads and you manage its width with user interaction in javascript.

Upvotes: 1

Related Questions