javascript - Page load Overlay -


i have site new users see contact when page loads. have tried numerous methods , gotten overlay ability hide , continue onto page not working.

    $(document).ready(function() {        $('#overlay').fadein();      });      $('button').click(function() {        $('#overlay').fadeout(200, "linear");      });       function opennav() {          document.getelementbyid("mynav").style.height = "100%";      }        function closenav() {          document.getelementbyid("mynav").style.height = "0%";      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <html><head>  <meta http-equiv="content-type" content="text/html; charset=utf-8">  <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>  </head>    <body>     <div id="mynav" class="overlay">       <h1>text</h1>       <button>hide</button>     </div>    </body>  </html>

if suggestions closing popup exist please share.

there bunch of ways hide element, being common 1 set

document.getelementbyid("mynav").style.display = "none"; 

and show again

// empty have 1 specified css or element default. // or "block", "inline", "inline-block"... whatever fits better. document.getelementbyid("mynav").style.display = ""; 

if hide height (is decision if have css transision, need fixed heights), need set element overflow hidden. default, if content of element bigger element size shown, .overlay class should have overflow: hidden hide it.

by way, using dynamic heights not using transitions. recommendation, use display way instead.

edit: noticed the id problem @rubenxfd points out. right. going main problem sure.

also, problem have run code

$('button').click(function() {   $('#overlay').fadeout(200, "linear"); }); 

before button element rendered, event won't attach don't exists. should attach when page ready, have move inside ready function, this:

$(document).ready(function() {   $('#mynav').fadein();   $('button').click(function() {     $('#mynav').fadeout(200, "linear");   }); }); 

notice difference.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -