Introduction

- click
- fadeIn/fadeOut
- preventDefault
- hide
click
- $("#div").click(function () {
- alert("click ");
- });
fadeIn/fadeOut
The .fadeIn()/.fadeOut() methods are used to animate the opacity of the matched elements. For this (PopUp window) I have shown animation with some transaction.
Syntax- .fadeIn([duration][,easing][,complete])
This method helps to prevent all the actions from being revoked, if this method is called, the default action will not be triggered. I have used this method to rollback the animation when we open the PopUp window.
This method helps to hide immediately, with no animation. And make the display none of that element. I have used this method to close the window.
JavaScript code and explanation
.fadeOut([duration][,easing][,complete])
- duration: A number or string value that will determine how long the animation will run.
- easing: A string indicating which easing function to use for the transaction
- complete: This is a function type and it calls the function when the animation is complete.
preventDefault
hide
- $(document).ready(function () {
- $('#myButton').click(function () {
- var id = '#dialog';
- var clgName = $('#cllg').val();
- $("#clg").val(clgName);
- var maskHeight = $(document).height();
- var maskWidth = $(document).width();
- $('#mask').css({ 'width': maskWidth, 'height': maskHeight })
- $('#mask').fadeIn(1000);
- $('#mask').fadeTo("slow", 0.8);
- var winH = $(window).height();
- var winW = $(window).width();
- $(id).css('top', winH / 2 - $(id).height() / 2);
- $(id).css('left', winW / 2 - $(id).width() / 2);
- $(id).fadeIn(2000);
- $('.window .close').click(function (e) {
- e.preventDefault();
- $('#mask').hide();
- $('.window').hide();
- });
- });
- });
This JavaScript code works in the following 3 steps:
- Getting the size of the window for the fade effect
- Set the pop-up window
- Close the pop-up window
CSS Code
- #mask {
- position: absolute;
- padding-left: 60px;
- padding-top: 80px;
- padding-bottom: 80px;
- padding-right: 50px;
- left: 0;
- top: 0;
- z-index: 9999;
- background-color: #808080;
- display: none;
- }
- #boxes .window {
- position: absolute;
- left: 0;
- top: 0;
- width: 580px;
- height: 300px;
- display: none;
- z-index: 9999;
- padding: 20px;
- background-color: white;
- border: 3px solid #79BBFD;
- border-radius: 10px;
- -webkit-border-radius: 10px;
- -moz-border-radius: 10px;
- }
- #boxes #dialog {
- padding: 10px;
- width: 580px;
- height: 300px;
- background-color: #ffffff;
- background-repeat: no-repeat;
- margin-top: 20px;
- }
- #headerBorder{
- height:25px;
- width:100%;
- background-color:#0026ff;
- color:white;
- font-size:18px;
- padding-top:3px;
- margin-bottom:20px;
- }
- #close{
- position:relative;
- float:right;
- text-decoration:none;
- padding-right:5px;
- cursor:pointer;
- }
In this CSS code, we are able to design a perfect dialog box and a background color.
HTML Code


Munesh SharmaPosted Nov 13, 2015, 5:46 AM
good one rajeev
FAROOKH MANSURIPosted May 22, 2015, 7:00 AM
it 's very helpful
Rama KrishnaPosted Jul 4, 2014, 10:54 AM
nice one
Sanjay SinghPosted Jun 24, 2014, 8:57 AM
nice article...