views:

121

answers:

2

There is an excellent code example on how to make nice jQuery Twitter style alerts here:

http://blog.codecrate.com/2009/10/twitter-style-alerts-in-rails.html

$(function () {
  var alert = $('.alert');
  if (alert.length > 0) {
    alert.show().animate({height: alert.outerHeight()}, 200);

    window.setTimeout(function() {
      alert.slideUp();
    }, 3000);
  }
});

However, one thing that the code doesn't include is functions to stick the alert div to the top of the window, no matter how far down the page the user has scrolled.

I have found a few examples but nothing seems to play nice with this existing code.

Any ideas?

+1  A: 

You can use the CSS style : position: fixed though I think IE has some issues with that (no surprise there..).

nickf
That would work until the page is scrolled. I need it to stick to the window top, no matter what position the page is scrolled to.
Robert Robb
`position:fixed` sets the position in relation to the window, not to the content. It is always visible.
toscho
A: 

Use position: fixed as well as top: 0px. That will keep the div at the top of the page, always. If you want it to the right or left, then add right: 0px or left: 0px to the div.

Arianna