Post image for Creating Message boxes using css with fadein Effects using jquery

Creating Message boxes using css with fadein Effects using jquery

by Hyder on March 27, 2010

in Html & CSS, Jquery

Using Message boxes is a great way to display warning, error or success messages. Facebook uses  a similar message box to display success messages. To Enhance the message box, I, have added different icons for different Message Status. I have also added a fade effect using Jquery. Before getting dirty into the codes, you can either download the file  or view an online demo.

View Demo Online || Download Source Code

Step 1 : Add The CSS Styles in your page Header

The CSS Style below Applies for all the Messageboxes.I have the specified the border to be 2 pixels of type solid with some margin and padding to position the text nicely in the message box.

I think the other css properties are pretty straight forward .


<style type='text/css'>
.successbox, .warningbox, .errormsgbox {
 font-weight:bold;
 border: 2px solid;
 margin: 10px 0px;
 padding:15px 10px 15px 70px;
 background-repeat: no-repeat;
 background-position: 10px center;
 width:600px;
}

The code below described the properties for each type of message box : Success , Error and Warning .
For each one a font weight,a color ,a background color and an icon is specified as Background Image.


.successbox {
 color: #4F8A10;
 background-color:#EDFCED;
 background-image:url('images/success.png');
}
.warningbox {
 color: #FFE222;
 background-color:#FAF9C9;
 background-image: url('images/warning.png');
}
.errormsgbox {
 color: #D8000C;
 background-color:#FDD5CE;
 background-image: url('images/error.png');
}

</style>

Step 2 : Add div in your body section

In your webpage body section add the following div with each a different CSS Class .


<body>
<div class="successbox" > This is a success message Box </div>
<div class="warningbox" > This is a warning message Box </div>
<div class="errormsgbox" > This is a Error  message Box </div>
 </body>

At this stage,you should have something like this :

Step 3 : Add the fade in effect using Jquery

To add a fade in effect jquery,make sure you have added the jquery library in the header section of your page .

<script language="javascript" src="js/jquery-1.3.2.js" type="text/javascript"></script>

Then Add this javascript code below that will cause a fade in effect with a duration of 2000 millisecond(2 seconds ) when the page loads .By default the 3 divs are hidden and after that it is displayed with a fade in effect .

<script>
$(document).ready(function() {// When the Dom is ready
$('.successbox').hide();//Hide the div
$('.warningbox').hide();
$('.errormsgbox').hide();

$(".successbox").fadeIn(2000); //Add a fade in effect that will last for 2000 millisecond
$(".warningbox").fadeIn(2000);
$(".errormsgbox").fadeIn(2000);

});
</script>

Step 4 : There’s no 4th step :)

If you have any suggestion,please let me know in the comment section .

Related Posts

  1. Creating a Fancy Search Feature with PHP,Mysql and Jquery
  2. Auto Load Page content every X second using Jquery
  3. Create fancy contact form with CSS 3 and jQuery
  4. Designing a form using pure CSS enhanced with Jquery

{ 4 comments… read them below or add one }

Anne April 6, 2011 at 3:01 pm

Hey Thanks – I’ve just started using jquery and had a bit of code for a message box that would fade out on click, but I wanted it to fade in too. I added your code and it worked like a charm. Many thanks!

Reply

Dayo July 27, 2011 at 6:10 pm

nice job…

Reply

wiqdgr8 September 5, 2011 at 1:19 pm

Thanks buddy….

Reply

Nurul Imam October 5, 2011 at 6:22 am

Hos to add box shadow to stylesheet ?

Reply

Leave a Comment

Previous post:

Next post: