- Tutorials / JavaScript
- Sunday, 26th Feb, 2012
Home » Tutorials » JavaScript » JQuery: Sticky Notification Bar
In this tutorial, we are going to teach you, the most easiest way to develop a sticky notification bar with JQuery. Such notification bar can be used to notify your user for latest updates, feedback message and etc. Please be sure to check out the demo, before we start the tutorial.
Note: You may interested on our previous tutorial – "JQuery: Sticky Footer" as well.
There is nothing much requirement for the HTML structure, what you need to do is adding 2 lines of following into your body of document:
<div id="note">Welcom to onlyWebPro.com</div> <p><a href="#" class="notify">Notify me</a></p>
Note: You must assigned an ID for the notification bar and a class for the button that trigger the notification.
Let’s give some styling to the notification bar:
#note {
position: absolute;
z-index: 101;
top: -100px;
left: 0;
right: 0;
background: #fde073;
text-align: center;
line-height: 2.5;
overflow: hidden;
-webkit-box-shadow: 0 0 5px black;
-moz-box-shadow: 0 0 5px black;
box-shadow: 0 0 5px black;
}
As you can see that, we set the default value of top to negative 100px, so that the notification bar will not appear every time the page load.
Now, it’s time to put some magic to make the notification works! First of all, please download the latest JQuery library from JQuery.com. Included the library in your document and let’s start our JQuery coding:
<script type="text/javascript" src="jquery.js"></script>
<script language="javascript">
$(document).ready(function() {
$(".notify").click(function(e) {
e.preventDefault();
$("#note").animate({top: 0}, 300, null);
//for css positioning prblem
$("#note").css("position", "fixed");
//Hide the bar
$notifyTimer = setTimeout(function () {
$("#note").animate({top: -100}, 1000, function() {
//change back to absolute
$("#note").css("position", "absolute");
});
}, 2000);
});
});
</script>
That’s all! Simple right? Just share out this simplest tutorial to your community and your friends! Let’s put some efforts to make a better web community! Stay updates with us via:
Please do let us know, if you have any thoughts / ideas on the comment section!
PHP: Object Oriented Programming for Absolute Beginners
HTML5 Canvas For Absolute Beginners – Part 4
Introduction To Device Orientation With HTML5
CSS3: Spinner Animation
Solving CSS Float's Problem
Create Facebook App Style Slide-Out Navigation
Build Intelligent Layout Using CSS Calc() Property
Catch It!
Make A jQuery Sticky Header In 5 Minutes
Koubachi Web Game
HTML5 Brain Challenge - Maths Edition