Drop down message on page load


Is there a good drop down message that loads at page load? Click and "X" to dismiss it. Sort of like a welcome mention. I can't seem to find one in my search so if anybody has one or can lead me in the right direction, I would appreciate.


How do you mean "drop down message"?

Do you mean something like a modal? (without the time delay)


I wasn't looking for a modal since I already have one on the page. I tried the modal and couldn't get it to work. Perhaps a conflict with existing modal code. When referring to drop down - you open the page and a message box comes down from top of page and then a message box is placed at a absolute position. I tried one at dynamic drive and couldn't get it to work, probably because it's an old example.


Got a link to the dynamic drive script?


Here's a CSS one (although it abuses the checkbox hack).

You could change the checkbox hack to a js class toggle instead and use mostly the same code.


Here is the link, thank you.


Not really sure what you mean by that. Can you clarify for me. Thank you.


That is indeed an old script and is pretty heavy for what it does (uses jQuery and jQuery.easing). It'd be a better idea to go with Paul's CSS solution.

If you're adamant that you want to use the dynamic drive script, can you post a link to a page where this is not working.


Both versions are deeply irritating to somebody who prefers keyboard navigation and expects Esc to dismiss pop-up windows. (And for some folk, it's not a preference but a necessity.)


Oh yeah, couldn't agree more. That was actually why I wrote the article linked above, as people seem to be set on doing this, so I at least wanted to present an accessible solution.


I would agree with you. PaulOB is a very smart and I am looking into to that, thanks.


The checkbox hack is useful but not really what a checkbox was designed for but does come useful in certain situations. However a lot of the time more complicated behaviours are probably best left to JS.

Here's a JS version of that message box although css does the heavy lifting.

@Pullo can probably tidy that JS up a bit though :slight_smile:

Added that in to the JS demo :slight_smile:


(function(d) {
  "use strict";

  var closeMessage = d.querySelector(".closeMe");
  var bodyEl = d.querySelector("body");
  closeMessage.addEventListener("click", function(event) {
  d.addEventListener("keyup", function(e) {
    if (e.keyCode === 27) bodyEl.classList.add("closeIt");

I'd assume only one of these per page, which makes the code a little simpler.


There's two classes of .closeMe actually. One on the X button in the message itself and one for the dark full page overlay itself so that the background outside of the message can be clicked to close as well.

I've added the last snippet in anyway thanks.

if (e.keyCode === 27) bodyEl.classList.add("closeIt");

I should have remembered the triple equals by now :slight_smile:


Oh missed that.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.