javascript - How to create a popup window with a form? -
here's login form in code snippet below. need open form in popup window clicking login link in menu. searched thru internet didn't found relevant answer. know should use javascript don't know how make right code. , should use plain js or jquery? why? thank you.
body { background: #a7a7a7; } .login__form { width: 320px; padding: 20px; background: #fff; border-radius: 5px; border-top: 5px solid #ff4e50; margin: 0 auto; } .login__form fieldset{ border: 0; } .login__form h3 { text-align: center; color: #666; font-size: 18px; text-transform: uppercase; margin-top: 0; margin-bottom: 20px; font-weight: bold; padding: 0; margin: 0; margin-bottom: 12px; } .login__form input { width: 100%; height: 42px; box-sizing: border-box; border-radius: 5px; border: 1px solid #ccc; margin-bottom: 20px; font-size: 14px; font-family: montserrat; padding: 0 20px 0 50px; outline: none; } .login__form input#username { background: #fff url('http://i.imgur.com/u0xmbmv.png') 20px top no-repeat; background-size: 16px 80px; } .login__form input#username:focus { background: #fff url('http://i.imgur.com/u0xmbmv.png') 20px bottom no-repeat; background-size: 16px 80px; } .login__form input#password { background: #fff url('http://i.imgur.com/qf83ftt.png') 20px top no-repeat; background-size: 16px 80px; } .login__form input#password:focus { background: #fff url('http://i.imgur.com/qf83ftt.png') 20px bottom no-repeat; background-size: 16px 80px; } .login__form input:active, .login__form input:focus { border: 1px solid #ff4e50; } .login__form input#button { width: 100%; height: 40px; background: #ff4e50; box-sizing: border-box; border-radius: 5px; border: 1px solid #e15960; color: #fff; font-weight: bold; text-transform: uppercase; font-size: 14px; font-family: montserrat; outline: none; cursor: pointer; margin: 0; padding: 0; } .login__form input#button:hover { opacity: 0.7; filter: alpha(opacity=70); }
<form name="login" class="login__form"> <h3>login</h3> <fieldset> <input type="text" value="" placeholder="username" id="username"> <input type="password" value="" placeholder="password" id="password"> <input type="submit" value="submit" id="button"> </fieldset> </form>
hi used simple jquery code
$(document).ready(function(){ $('.login__form').hide(); $('.click').on('click', function(){ $('.login__form').show(); }); $('.closepopup').on('click', function(){ $('.login__form').hide(); }) });
body { background: #a7a7a7; } .closepopup{position: absolute; right: 8px; top: 7px; cursor: pointer; border: solid 2px red; border-radius: 50%; font-size: 14px; font-family: arial; padding: 2px 6px;} .login__form { width: 320px; padding: 20px; background: #fff; border-radius: 5px; border-top: 5px solid #ff4e50; margin: 0 auto;position:relative; } .login__form fieldset{ border: 0; } .login__form h3 { text-align: center; color: #666; font-size: 18px; text-transform: uppercase; margin-top: 0; margin-bottom: 20px; font-weight: bold; padding: 0; margin: 0; margin-bottom: 12px; } .login__form input { width: 100%; height: 42px; box-sizing: border-box; border-radius: 5px; border: 1px solid #ccc; margin-bottom: 20px; font-size: 14px; font-family: montserrat; padding: 0 20px 0 50px; outline: none; } .login__form input#username { background: #fff url('http://i.imgur.com/u0xmbmv.png') 20px top no-repeat; background-size: 16px 80px; } .login__form input#username:focus { background: #fff url('http://i.imgur.com/u0xmbmv.png') 20px bottom no-repeat; background-size: 16px 80px; } .login__form input#password { background: #fff url('http://i.imgur.com/qf83ftt.png') 20px top no-repeat; background-size: 16px 80px; } .login__form input#password:focus { background: #fff url('http://i.imgur.com/qf83ftt.png') 20px bottom no-repeat; background-size: 16px 80px; } .login__form input:active, .login__form input:focus { border: 1px solid #ff4e50; } .login__form input#button { width: 100%; height: 40px; background: #ff4e50; box-sizing: border-box; border-radius: 5px; border: 1px solid #e15960; color: #fff; font-weight: bold; text-transform: uppercase; font-size: 14px; font-family: montserrat; outline: none; cursor: pointer; margin: 0; padding: 0; } .login__form input#button:hover { opacity: 0.7; filter: alpha(opacity=70); } .click{float:left;cursor:pointer;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <button class="click">login popup</button> <form name="login" class="login__form"> <span class="closepopup">x</span> <h3>login</h3> <fieldset> <input type="text" value="" placeholder="username" id="username"> <input type="password" value="" placeholder="password" id="password"> <input type="submit" value="submit" id="button"> </fieldset> </form>
Comments
Post a Comment