Please try jQuery UI dialog
Here is the forms demo
For mobile use, have a look at jQuery Mobile - Creating dialogs
Answer from mplungjan on Stack OverflowVideos
What Is a Popup Form?
How Do You Create a Popup Form?
How Do You Create a Popup Form in WordPress?
Please try jQuery UI dialog
Here is the forms demo
For mobile use, have a look at jQuery Mobile - Creating dialogs
Live Demo
Sounds like you might want a light box,and since you didnt tag your question with jQuery included is a pure JS example of how to make one.
JS
var opener = document.getElementById("opener");
opener.onclick = function(){
var lightbox = document.getElementById("lightbox"),
dimmer = document.createElement("div");
dimmer.style.width = window.innerWidth + 'px';
dimmer.style.height = window.innerHeight + 'px';
dimmer.className = 'dimmer';
dimmer.onclick = function(){
document.body.removeChild(this);
lightbox.style.visibility = 'hidden';
}
document.body.appendChild(dimmer);
lightbox.style.visibility = 'visible';
lightbox.style.top = window.innerHeight/2 - 50 + 'px';
lightbox.style.left = window.innerWidth/2 - 100 + 'px';
return false;
}
Markup
<div id="lightbox">Testing out the lightbox</div>
<a href="#" id="opener">Click me</a>
CSS
#lightbox{
visibility:hidden;
position:absolute;
background:red;
border:2px solid #3c3c3c;
color:white;
z-index:100;
width: 200px;
height:100px;
padding:20px;
}
.dimmer{
background: #000;
position: absolute;
opacity: .5;
top: 0;
z-index:99;
}
Hey everyone, I'm creating my very first CRUD app! HTML, CSS, JS and Express with ejs.
I want to create a popup login/sign up form, similar to the one on Twitter, and I was wondering what the best way to go about this was:
Shall I write all the html, hide it and add an event to the button which toggles the class that makes the overlay and form appear? Or
Just write the container in html, and add an event to the button which fires a function that creates all the elements and appends them? (no inner html)
I was considering the second option, because this form is going to be in different places (home page CTA, show page and index page of someone isn't signed in, etc), so I was thinking that having a function build it out would be more functional (pun not intended) but I've been hearing that using js to create html should be kept to a bare minimum, so I'm curious to hear some more expert opinions.
You can use jquery UI:
$(function() {
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#opener").click(function() {
$("#dialog").dialog("open");
});
});
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);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<div id="dialog">
<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>
</div>
<button id="opener">Log In</button>
Of course you can modify this code to align with your needs.
Hi now used to simple jquery code as like this
$(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>