Mootools Splash Screen

February 2, 2010 | In: Code, Mootools, Scripts

Splash ScreenEvery now and then you get a client that absolutely insists on having a “splash screen“. However hard you try to convince them that it is not good for SEO (search engines like content and links) or for visitors (after all, you are wasting their time), they refuse to see it your way and insist on having it.

I had one of them this week and, rather than spending the time and energy on trying to persuade the client, I decided to have a go at making one with my favorite javascript Library – Mootools :)

To this end, I came up with the following class. It is really quite simple and could no doubt be improved and features be added but I thought that I would share it anyway.

See Demo

The HTML:

<div id="splash">
  Splash Screen contents (image, text, advert etc.)
  <div id="btCloseSplash">close now</div>
</div>

The CSS:

#splash {
  position: absolute;
  z-index: 9991;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  background-color: #FFF;
  text-align:center;
  display:none; /*hide it incase the user has javascript disabled*/
  color:#000;
}

The MOOTOOLS class

var SplashScreen = new Class({
  Implements: Options,
  options: {
    'delay':5000 ,
    'showOnce':true
  },
  initialize: function(element, options){
    this.setOptions(options);
    this.splash=document.id(element);
    if(this.options.showOnce){
      // check cookie to see if splash has been shown in this session
      var splashCookie = Cookie.read('showSplashCookie') || 'yes';
      if(splashCookie=='yes'){
        this.showSplash();
        Cookie.write('showSplashCookie', 'no');
      }
    }else{
      this.showSplash();
    }
  },
  showSplash:function(){
    this.splash.setStyles({
      'height':window.getScrollHeight(),
      'display':'block',
      'opacity':'1'
    });
    // iframe for ie6 <Bah! Humbug!>
    if(Browser.Engine.trident4){
      var iframe2 = new Element('iframe',{
        styles:{'position':'absolute','width':'120%','height':'120%','top':'-10%','left':'-10%'},
	height:'100%',
	width:'100%',
        frameborder:0
      }).setOpacity(0).inject(this.splash,'top');
    }
    this.closeSplash.delay(this.options.delay, this);
  },
  closeSplash: function(){
    this.splash.fade('out');
  }
});

Initiate the Class

window.addEvent('domready', function() {
  var splash = new SplashScreen('splash',{'delay':'5000','showOnce':false});
});

Giving the visitor the chance to just get on with it is always a good idea so we can call the closeSplash method like this…

Button to close the Splash Screen

window.addEvent('domready', function() {
  var splash = new SplashScreen('splash',{'delay':'5000','showOnce':false});
  document.id('btCloseSplash').addEvent('click',function(){
    splash.closeSplash();
  });
});

Pretty simple stuff really and, as the splash screen is set to display:none in the css, it will only be shown if the browser has Javascript activated.
I have also thrown a cookie in there which can be set to be used or not by an “option” so that the Splash Screen will only be shown once per session.

Now, should I make this my first addition to the Mootools Forge….?

Availability Calendar.

Post to Twitter



16 Responses to Mootools Splash Screen

Avatar

derschreckliche

February 3rd, 2010 at 00:19

Cool stuff.

I got a usability suggestion for you: You could make the Demo-Button stand out more. Would have not noticed it if i didn’t expect to find one here.

Avatar

Peter

March 8th, 2010 at 10:45

Hi,
Your splash looks great! You say it is not good for SEO. I thought the thing search engines did not like about splash pages was that they often redirect to another page and as such were regarded as spam-sites which became de-indexed as a resut.

But your solution has all code in the same page so why would your mootools-solution above not be SEO-friendly?

Or is there something else that search engines hate about splash screens that would include the one above as well?

Thanks!

Avatar

Chris

March 8th, 2010 at 11:10

Hi, thanks for your comments.
By saying that splash screens are not good for SEO I was referring to the “traditional” ones which place a page, often created in flash, before the content.
The problem being that the search engines find them, find no content, and move on.
That was the reason why I did this little script for a client. As the screen is initiated by javascript, the search engines never see it (other than any text content it might contain) so it doesn’t interfere with the SEO potential of the page.

Avatar

Peter

March 8th, 2010 at 17:14

Hello again, thanks for replying so fast.
Is it possible to have the splash screen fade in over a couple of seconds, rather than being visible from scratch? I am trying to change the display:none and use “fade in” but my javascript knowledge is not very good so it does not work…
Thanks!

Avatar

Chris

March 8th, 2010 at 17:48

For some strange reason I can’t connect to my ftp at the moment.
However this should work for a simple fade in:

Replace these lines (22 to 26 in my demo code above):
this.splash.setStyles({
‘height’:window.getScrollHeight(),
‘display’:'block’,
‘opacity’:’1′
});
with this:
this.splash.setStyles({
‘height’:window.getScrollHeight(),
‘display’:'block’
}).fade(‘in’);

You will notice that I haven’t defined a fade in time, just used the default one that mootools provides.
To alter this you will need to use the complete mootools fx.tween() function to define the options.

Chris

Avatar

Peter

March 8th, 2010 at 18:12

Hi, thanks again.
I did not work but I found out why… It needs to set ‘opacity’:’0′ when going display:block otherwise it shows up instantly.
I guess now alls I have to do is to create another div with just background color that can block out the main content all the time (of course it got visible during the initial fade in (hadn’t thought about that)).
Ciao!

Avatar

popujax

March 25th, 2010 at 18:53

Hi there,

Great and very useful post sir! I wanna use your little hack for my site where I need to display sort of verification age splash page. The only problem I can see with your splash script is that it automatically fades out after 5sec.

Can I turn it off somehow? So after someone hits my site they will presented with a splash with 2 buttons(Yes I am over 18 or No) and it won’t disappear after 5sec . I want this splash to stay there as long as none of the options are clicked. Is it possible?

Thanks!

Avatar

Chris

March 25th, 2010 at 20:21

Hi there,
To remove the auto-close feature of the spashscreen you just need to remove this line from the js file (line 64):

this.closeSplash.delay(this.options.delay, this);

You can then close the splash screen by calling the public function “closeSplash” once your form has is submitted.

Chris

Avatar

Juraj

March 25th, 2010 at 21:57

Demo is broken. JS with Splash Screen is missing.

Avatar

Chris

March 25th, 2010 at 22:02

oppps, sorry about that.
I was just trying something for @popujax and forgot to put it back :(

Fixed now.
Chris

Avatar

popujax

March 25th, 2010 at 23:44

wow! what can i say sir. It works like a charm. A bit strange though as I am pretty sure I removed this line before when I was playing with this script. Anyway thanks a lot for your help sir and see you in the internets!

Avatar

Juraj

March 29th, 2010 at 20:32

Cheers Chris, looks nice :) Even in Opera.

Avatar

jeremy

May 6th, 2010 at 15:34

Is it possible to trigger the fade out x seconds after a video has played?

Avatar

Chris

May 6th, 2010 at 16:53

Hi,
If you are able to detect when the movie has finished, I don’t see why not.
You just need to call the public function closeSplash() once the video has ended.
However, I am not sure how you would be able to detect the end of the video…

Avatar

robb

August 25th, 2010 at 15:26

hey chris, nice work! I was wondering if there is a way to reset the cookie after a period of time.

Avatar

Chris

August 25th, 2010 at 15:54

Hi,
You can set the duration of the cookie by modifying the actual Mootools Class (I should possibly make this an option)

Find this line:
Cookie.write(‘showSplashCookie’, ‘no’)
and change it to this:
Cookie.write(‘showSplashCookie’, ‘no’, {duration: 1})
Where “1″ is the number of days. If you don’t set the duration (as per the default) the cookie should only last the length of the browser session.

Comment Form

recomended

GabinohomeServWise - Low cost, reliable and fast hosting with 24/7 supportAre my sites up?

in short...

  • 1 more day until I am officially take a weeks holiday. Off to Ronda @VallecilloRonda with my family and my parents who are over from the UK. 1 week ago
  • Having some fun with the Google maps api v3 - it has been a while since I did any mapping :) 1 week ago
  • Just finished my evening run and got a surprise message from Lance Armstrong on my iPod congratulating me on completing my longest run :) 2 weeks ago
  • Another client has just offered me a retainer... a couple more of these and I'll be sorted ;) 3 weeks ago
  • It is a public holiday in Spain today. No work will be being done by me (well, OK, maybe just a little bit). 3 weeks ago
  • More updates...
Contact