In our projects some time or another requirement comes to display error notifications on top of the page.
This tutorial explains exactly the same.
We have some error or alert notifications that you wants user to get alerted on top of the page, well pretty simple.
First lets see the HTML.
<div id='message'>
<ul id="ticker">
<li>
1is jQuery plugin that gives you freedom to easily display your data as graphs. There are three types of graphs: simple, multi and stacked.
<a href="#" class="close-notify">X</a>
</li>
<li>
2Learn how to create image gallery in 4 lines of Jquery
<a href="#" class="close-notify">X</a>
</li>
<li>
3is easy-to-use jQuery plugin for displaying your photos as slideshow with fancy transition effects.
<a href="#" class="close-notify">X</a>
</li>
<li>
4is AJAX graph plugin for MooTools which support two types of graphs, simple bar and stacked bar graph.
<a href="#" class="close-notify">X</a>
</li>
</ul>
</div>
We have created the division with the required li's
now some Jquery stuff, add this above your ending body tag
<script>
$(document).ready(function() {
$("#message").fadeIn("slow");
$("#message a.close-notify").click(function() {
if($('#ticker li').size() == 1)
$("#message").fadeOut("slow");
else
//$(this).closest('li').remove();
$(this).closest('li').fadeOut('slow', function(){ $(this).remove(); });
tick();
return false;
});
function tick(){
$('#ticker li:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
//$('#ticker li:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
}
setInterval(function(){ tick () }, 7000);
});
</script>
Now some styling
#message {
position:fixed;
top:0px;
left:0px;
width:100%;
z-index:105;
font-weight:bold;
font-size:100%;
padding:0px;
background-color: #111;
color: #f0f0f0;
display: none;
}
#ticker {
height: 25px;
overflow: hidden;
}
ul#ticker li{
list-style:none;
background:url(alert.jpg) no-repeat;
float:left;
text-align: center;
width: 95%;
}
.close-notify {
white-space: nowrap;
float:right;
margin-right:9px;
color:#fff;
text-decoration:none;
border:2px #fff solid;
padding-left:3px;
padding-right:3px;
padding-top: 0px;
}
The list items will ticker, closing one will show the next and last one will make all the bar go disappear.
You can download the complete zip file from here
Happy Coding !! :)
This tutorial explains exactly the same.
We have some error or alert notifications that you wants user to get alerted on top of the page, well pretty simple.
First lets see the HTML.
<div id='message'>
<ul id="ticker">
<li>
1is jQuery plugin that gives you freedom to easily display your data as graphs. There are three types of graphs: simple, multi and stacked.
<a href="#" class="close-notify">X</a>
</li>
<li>
2Learn how to create image gallery in 4 lines of Jquery
<a href="#" class="close-notify">X</a>
</li>
<li>
3is easy-to-use jQuery plugin for displaying your photos as slideshow with fancy transition effects.
<a href="#" class="close-notify">X</a>
</li>
<li>
4is AJAX graph plugin for MooTools which support two types of graphs, simple bar and stacked bar graph.
<a href="#" class="close-notify">X</a>
</li>
</ul>
</div>
We have created the division with the required li's
now some Jquery stuff, add this above your ending body tag
<script>
$(document).ready(function() {
$("#message").fadeIn("slow");
$("#message a.close-notify").click(function() {
if($('#ticker li').size() == 1)
$("#message").fadeOut("slow");
else
//$(this).closest('li').remove();
$(this).closest('li').fadeOut('slow', function(){ $(this).remove(); });
tick();
return false;
});
function tick(){
$('#ticker li:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
//$('#ticker li:first').slideUp( function () { $(this).appendTo($('#ticker')).slideDown(); });
}
setInterval(function(){ tick () }, 7000);
});
</script>
Now some styling
#message {
position:fixed;
top:0px;
left:0px;
width:100%;
z-index:105;
font-weight:bold;
font-size:100%;
padding:0px;
background-color: #111;
color: #f0f0f0;
display: none;
}
#ticker {
height: 25px;
overflow: hidden;
}
ul#ticker li{
list-style:none;
background:url(alert.jpg) no-repeat;
float:left;
text-align: center;
width: 95%;
}
.close-notify {
white-space: nowrap;
float:right;
margin-right:9px;
color:#fff;
text-decoration:none;
border:2px #fff solid;
padding-left:3px;
padding-right:3px;
padding-top: 0px;
}
The list items will ticker, closing one will show the next and last one will make all the bar go disappear.
You can download the complete zip file from here
Happy Coding !! :)
Comments
Post a Comment