Mostly people are still confuse to make a simple popup options,however it is nothing except a few lines of code.I am sharing a popup menu that appears on a button click and can be close by a close button in the popup option.A few things that this popup have are:
- The user cannot scroll when popup appear.
- The user cannot click anywhere else on screen when popup is their.
- The popup appear and disappear in a smooth transition.
- No matter on which scroll level does the popup triggered,the popup will all ways be in the centre of screen.
HTML
<div class='blank'></div>It is not necessary that the
<div class='close-popup'><span>Close</span></div>
The Popup content will go here
</div>
<div class='content'>
This is the body part
</div>
popup
and blank
are the siblings
of the main content,they could be child
too.But it should be noted that the content must not have a position set to relative,in some cases it won't cover the whole screen and will create difficulties for you.However,still you have a simple solution to use these elements as a sibling
.CSS
.blank{If you have noticed,then let me tell you that you will design each and everything of the popup in the CSS because it will decrease the Javascript and second it is easy to make.Secondly, set the
position:fixed;
width:100%;
height:100%;
background:rgba(0,0,0,0.7);
top:0;
left:0;
display:none;
}
.popup{
position:fixed;
display:none;
top:20%;
left:25%;
padding:25px;
width:50%;
background:#eee;
}
.close-popup{
display:block;
margin:20px 0;
text-align:right;
}
.close-popup span{
padding:5px;
background:#ddd;
cursor:pointer;
}
.trigger{
display:inline-block;
padding:10px;
background:#333;
color:#fff;
margin:10px;
cursor:pointer;
float:left;
}
popup
and blank
to display none
so that using Jquery we can break the property.Jquery
$('.trigger').click(function(){As I told,you just need to overcome on the script using
$('.blank,.popup').show(500);
$('body').css("overflow","hidden");
});
$('.close-popup span').click(function(){
$('.blank,.popup').hide(500);
$('body').css("overflow","auto");
});
CSS
to make this not the Jquery
. Jquery
will only do two functions:- Will break the property of
display none
. - Will change the property of
body
to make it non-scrollable.
Hi, I would like to subscribe for this web site to get most up-to-date updates, so where can i do it please help.
ReplyDeleteHere is my web site kitchen remodeling