Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rahuldass/5f53c6301c273c3b9a6f to your computer and use it in GitHub Desktop.
Save rahuldass/5f53c6301c273c3b9a6f to your computer and use it in GitHub Desktop.
Jquery Notification Bars that can be dismissed on click #jquery

###Jquery Notification Bars that can be dismissed on click

Demo Link :- http://jsfiddle.net/rahuldass/mj3UQ/7/


Make it the first <div> under the <body> tag.

HTML

<div id="notify"></div>
<div id="content">
    <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
</div>

CSS

#notify {
    position:relative;
    width:100%;
    background-color: tomato;
    height:30px;
    color:white;
    display:none;
    text-align:center;
    padding:12px;
    font-size:1em;
    line-height:1em;
    font-family: Arial, sans-serif;
    border:1px solid red;
    cursor:pointer;
}

p {
    margin: 20px;
}

JavsScript

$('#notify').click(function() {
    $(this).slideUp().empty();
});

$(function(){
    $('#notify').html('Welcome to the test page!').slideDown();
});

Multiple Notification

If you want multiple notifications, change #notify to .notify and stack em up. Something like this:


Demo Link :- http://jsfiddle.net/rahuldass/6j8Lk/3/


HTML

<div id="content">
    <p>
        Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
    </p>
</div>

CSS

.notify {
    position:relative;
    width:100%;
    background-color:tomato;
    height:30px;
    color:white;
    display:none;
    text-align:center;
    padding:5px;
    font-size:1em;
    line-height:1em;
    font-family: Arial, sans-serif;
    border:1px solid red;
    cursor:pointer;
}

p {
    font-family:Arial, sans-serif;
    margin:20px;
}

JavsScript

$('.notify').live('click',function() {
    $(this).slideUp('fast',function(){$(this).remove();});
});

$(function(){
    notify('You have earned the JQuery badge!');
    notify('You have earned the Super Awesome badge!');
});

function notify(msg) {
    $('<div/>').prependTo('body').addClass('notify').html(msg).slideDown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment