views:

2244

answers:

8

I would like to add a popup message like the one that appears on stackoverflow when I am not logged in and I try to use voting buttons.

What is the best method for achieving that? Is it done using a jquery library?

+3  A: 

I use jqModal, easy to use and you can achieve some great effects

Juan Manuel
+3  A: 

Also checkout jQuery UI Dialog

jonstjohn
+1  A: 

Using the ModalPopup in the AJAX control toolkit is another way you can get this effect.

patjbs
please comment the downvote, using a modal popup is perfectly valid for what the original question asked.
patjbs
A: 

There is similar question. You might want to check that as well.

Shoban
Those answers are too vague.
Jim G.
A: 

As a curious developer, I would view the source here and see how it works and then adapt it to my project. This is the best way to learn.

Josh Stodola
This website is built using ASP.NET (ASP.NET MVC to be more specific) which means that he can't actually see whats going on because there is code running on the server. Also they linked to their .js files on the server so he wouldn't be able to see them either.
Lucas McCoy
All of the functionality he is referring to is on the client-side, and he has access to all the code he needs to replicate it. Im not sure what you are talking about.
Josh Stodola
+75  A: 

EDIT: The code below shows how to replicate the bars that show at the top of the screen when you get a new badge, first come to the site, etc. For the hovering dialogs that you get when you try to comment too fast, vote for your own question, etc, check out this question where I show how to do this or just go straight to the example.


Here's how Stackoverflow does it:

This is the markup, initially hidden so we can fade it in:

<div id='message' style="display: none;">
    <span>Hey, This is my Message.</span>
    <a href="#" class="close-notify">X</a>
</div>

Here are the styles applied:

#message {
    font-family:Arial,Helvetica,sans-serif;
    position:fixed;
    top:0px;
    left:0px;
    width:100%;
    z-index:105;
    text-align:center;
    font-weight:bold;
    font-size:100%;
    color:white;
    padding:10px 0px 10px 0px;
    background-color:#8E1609;
}

#message span {
    text-align: center;
    width: 95%;
    float:left;
}

.close-notify {
    white-space: nowrap;
    float:right;
    margin-right:10px;
    color:#fff;
    text-decoration:none;
    border:2px #fff solid;
    padding-left:3px;
    padding-right:3px
}

.close-notify a {
    color: #fff;
}

And this is javascript (using jQuery):

$(document).ready(function() {
    $("#message").fadeIn("slow");
    $("#message a.close-notify").click(function() {
        $("#message").fadeOut("slow");
        return false;
    });
});

And voila. Depending on your page setup you might also want to edit the body margin-top on display.

Here is a demo of it in action.

Paolo Bergantino
Re-reading the question I don't think this is what the Op wanted. I think he's looking for the boxes that appear as notices around the site near whatever you do. I guess I'll leave this up anyways.
Paolo Bergantino
Paolo, Thanks for leaving this up! I think this may work quite a bit better than what I was using for this action.
Jayrox
While not the answer, equally helpful :P
rball
been wondering how to do this for a while now. Thanks!
ranomore
+1 for the demo
Alex B
You also need to set a cookie when you click the X so that it doesn't keep appearing as you go to more pages.
DisgruntledGoat
@Goat: The way I use this I only show the message once even if they don't click on the X, so I take care of it on the server-side.
Paolo Bergantino
I wish I could star an answer too. Thanks for this excellent entry!
cringe
A: 

Do you guys know if there is a drupal module which would allow me to do the cool sliding drop down messages like 'First time here? Check out the FAQ!'?

Thanks in advance!

HS
A: 

How do you make message bar show only once and not-repeat its appearance if user closes the bar and then reloads the page or if user closes the bar and navigates to another page? Basically seeking to have the same functionality as on StackOverFlow, where if visitor closes the bar on one page... it remains closed on all the subsequent pages of the site.

Guy
write out a cookie. Take a look at Tim Heuer's blog. He does something very similar there. http://timheuer.com/blog/
Scott