Does jQuery have a plugin to display a “message bar” like the Twitter “wrong password” bar at the top of screen?

前端 未结 2 731
故里飘歌
故里飘歌 2020-12-03 03:28

Twitter will pop down a message bar at the top of the screen say \"Wrong password\" and after 10 seconds, it will slide up and disappear. Chrome also shows \"Do you want to

2条回答
  •  暖寄归人
    2020-12-03 04:14

    You can do this with just a few lines of code, like this:

    ​​​​function topBar(​​​message) {
      $("
    ", { 'class': 'topbar', text: message }).hide().prependTo("body") .slideDown('fast').delay(10000).slideUp(function() { $(this).remove(); }); }

    Then just give the class you use some styling, for example:

    .topbar { 
        background: #990000; 
        border-bottom: solid 2px #EEE; 
        padding: 3px 0; 
        text-align: center; 
        color: white;
    }​
    

    You can view a working demo here, tweak as needed :) This creates a

    on the fly, adds it to the top of the body, so no funky positioning to worry about, this should be just fine in IE6. When it's finished it'll slideUp and remove the
    it created to cleanup. You can add a click handler to remove it instantly, etc, whatever your needs are.

提交回复
热议问题