Apple’s Website’s Blackout Effect: Revised

Note: For a list of revisions made, click here.

First of all, Happy Halloween to everyone, may all of your teeth rot from the gargantuan amount of candy that you will be consuming. I know I sound somewhat morbid, but the future doesn’t seem to be going to go well for me.

Well, with that said, if you’ve recently visited Apple’s website, you should’ve noticed that I made a cheap replica of their blackout effect. When I say cheap I mean it’s like those fake iPhones, similar, but not quite similar.

I tried to dissect Apple’s website source code but being the JavaScript illiterate that I am, I couldn’t find out much about the works of it. I searched on Google in hopes of finding the same effect that someone has made; But the only ones that showed up were paid ones, ranging from £5.00 to €5.99 ($8.02 to $8.35). I wasn’t going to pay for something simple like that. So I decided to make one my own. I have no prior knowledge on jQuery but how hard could it be right? In the end I took me about a day and a half to figure it out. FML

But because I hate people who charge money for simple and easy things like these, I am going to share my finding with everyone, and you will be allowed to take my code and do whatever you want with it, but I hold no responsibility if you fuck up. (Not that it’s possible as far as I know) The HTML code is validated as HTML5 and the CSS is validated as CSS 2.1. The code has been tested to be working on Safari 5.0.2, Firefox 4.0b6, Google Chrome 7.0.517.41, and Opera 10.63. I have no plans to test it on IE, but it’d be great if it works

DemoDownload (65KB)Demo [IE]Download [IE] (65KB)

Overlay HTML

The overlay is the black layer that covers the website when the fade in is executed. I created a different section just for that purpose

<section>
	<article>
		<div></div>
		<p>Happy Halloween!</p>
		<p>from seanooi.net</p>
	</article>
</section>

The empty div in line 3 is for the blackout image. In my demo, it would be the image with a left and right hand print on each side of the image. The div element is used to ensure that the image will display on Opera as well

Overlay CSS

body>section
{
	position: fixed;
	top: 0;
	left: 0;
	background-color: #000;
	width: 100%;
	height: 100%;
}

The position is set to fixed so that the background color covers the entire page and not only the viewable area of your web browser.

body>section>article>div
{
	background: url('images/demo-blackout.png');
	width: 625px;
	height: 200px;
	margin: 1em auto 0;
	display: none;
}

body>section>article p
{
	text-align: center;
	font-family: Helvetica, Verdana, Sans-Serif;
	color: #cc1100;
	font-size: 48pt;
	margin:.5em auto 0;
	display: none;
}

These 2 chunks of CSS is pretty much just positioning the image and text. But be sure that elements that you wish to fade in has to have the display: none; property in order for it to be able to fade in.

body>section>article, body>article
{
	display: none;
	width: 980px;
	margin: 0 auto;
}

These 2 tags have been set to display: none; as well to avoid the blackout images from flickering before it starts to fade in. body>article will be explained below

Main HTML

The main part of the page is just a few short lines for this demo.

<article>
	<div></div>
	<p>This is a demo mimicking <a href="http://www.apple.com">Apple's</a> blackout effect</p>
</article>

Main CSS

The body>article tag has been set to display: none; so that the page will not show before the blackout effect is ready, so we set it to fade in after the blackout effect executes.

body>article>div
{
	background: url('images/demo.png');
	width: 525px;
	height: 200px;
	margin: 1em auto 0;
}

body>article>p
{
	text-align: center;
}

Be sure that you position your page image below the blackout image so that when the blackout image fades out, it will be seen as if the image stayed.

jQuery

This is the part where I had a little difficulty with because I wasn’t literate in the language, but Google has been a big help to helping me find what I needed.

$(document).ready(function (){
	$('section').find('article').delay(1000).fadeIn(1);
	$('section').find('div').delay(1000).fadeIn(2000);
	$('section').find('p').delay(3000).fadeIn(2000);
	$('body').find('article').delay(4000).fadeIn(2000);
	$('section').delay(6000).fadeOut(2000);
});

As you can see, it’s pretty self explanatory. Take line 2 as an example

$('look for an element X').find('find the element within element X').delay(time it takes to execute the next command in milliseconds).fadeIn(time it takes to fade in in milliseconds);

In line 5 we give body>article a 4 second delay before it fades in behind the overlay layer.

That’s all there is to it. If anyone has a better way of doing the same thing I did, please do drop me a message. I will be very interested to know about it. Any comments are welcome too.

Revision

November 12, 2010:

  1. I received a request yesterday for an IE version of my code, so I have just revised and uploaded a new set of codes that are compatible with IE.
  2. The post will still be explained in HTML5, so if you decide to go with the IE version, you’re on your own. But the code should be fairly straightforward.

Comment Feature Back Again (Revised for WordPress 3.2)

When I first created this theme, I contemplated between having or not having the comment function implemented. In the end I went with a blog without the comment feature; Only the trackback function was enabled.

I initially thought the contact form was good enough as a means of communication, and that if no one knows how to use it, they don’t deserve to be using the internet. But I was told that to use the contact form for a simple comment would be overkilled. In addition to that someone asked for me to put up the comment section again. So I set out to think of ways to make my comment section different from the default layout yet fool-proof.

I thought for awhile and decided to make the comment page a separate page, meaning one whole page just for posting comments. The idea sounded easy, but it was actually more work then I expected it to be. For someone who had absolutely no prior knowledge to PHP, it was almost like making James Bond follow the law; Not impossible, just hard.

I searched online and came across a site that explained exactly what I wanted to do, but the instructions were pretty messy and static, so hopefully my version of instructions will be of use to anyone who wish to do the same.

In my version, you will be editing 5 files instead of the original posts’ 3 files, and with the link to the comments page left untouched. Files from your current theme folder will be:

  • single.php
  • functions.php
  • comments.php

The 2 other files will be from your /wp-includes directory. If you’ve just updated your WordPress script, these will be the only 2 files you need to edit. Click here to skip the themes section.

  • comment-template.php
  • link-template.php

Theme Folder

  1. First step is to go into your themes folder and open up the folder of your current theme.
  2. Open up single.php and wrap the following code around your single post syntaxes, within the loop
< ?php if (!isset($_GET['show'])) { ?>
	[single post codes here]
<?php } ?>
  1. Next, look for <?php comments_template(); ?> and replace it with the following code
<?php if (isset($_GET['show']) && $_GET['show'] == "comments") { ?>
	<?php comments_template(); ?>
<?php } ?>
  1. You can now go ahead and close your single.php file after saving your changes.
  2. Now open up your functions.php file and add the following function.
function curPageURL() {
	$pageURL = 'http';
	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
		$pageURL .= "://";
		if ($_SERVER["SERVER_PORT"] != "80") {
			$pageURL .= $_SERVER["SERVER_NAME"].":" .$_SERVER["SERVER_PORT"] .$_SERVER["REQUEST_URI"];
		} else {
	$pageURL .= $_SERVER["SERVER_NAME"] .$_SERVER["REQUEST_URI"];
	}
	return $pageURL;
}
  1. Save your changes and open up your comments.php file and add the following code before the </form> tag, which is usually near the end of the file
<?php if (function_exists('curPageURL')) { ?>
	<input type="hidden" name="redirect_to" value="<?php echo curPageURL() ?>" />
<?php } ?>

You’re done editing your theme files. Next we’ll move on to the wp-includes directory.

/wp-includes

  1. Open up your comment-template.php file
  2. scroll to line 507. Replace #comment- with:
?show=comments#comment-
  1. Scroll to line 519. Replace #comments with:
?show=comments#respond
  1. Scroll to line 1001. Replace #respond with:
?show=comments#respond
  1. Scroll to line 1062. Replace # with:
?show=comments#
  1. Scroll to line 1113. Replace #$respond_id with:
?show=comments#$respond_id
  1. Scroll to line 1206. Replace #comment- with:
?show=comments#comment-

You’re now done with comment.template.php. Moving on…

  1. Now open up link-template.php
  2. Scroll to line 1767. Replace #comments with:
?show=comments
  1. Scroll to line 1881. Replace #comments with:
?show=comments

If everything went well and accordingly, the <?php comments_popup_link(); ?> function should now link to your comments page by appending ?show=comments#respond to your single post permalink rather than just #respond.

If any of you noticed, the trackback link that was previously under every post has been taken away. The reason for that is because I still have yet to figure out how to put trackbacks on a page by itself because posting it as a comment will be a mess and in addition to that, trackbacks have no avatars, therefore ruining my whole comment section design.

Audio For Everybody!

When The Love Falls by Sean OoiDownload Audio: Audio Format "MP3" | Audio Format "OGG"

Prologue

A few posts back I used the new HTML 5 video tag to display a video. That chunk of code was written by Kroc Camen and is compatible across most major browsers, including IE and the iPhone. One of the reasons I like it is because there is no JavaScript involved, making it lightweight.

It was his Video for Everybody post that inspired me to write this post. I figured since there's a cross-browser compatible code for the video tag, it would only be right to have one for the audio tag as well; A simple Google search came up with one related site that was very poorly written, so I decided to write one myself, based heavily on Kroc's code.

I've tested my codes on the iPhone and on common web browsers which includes Firefox, Safari and Opera on both Windows and Mac OS X, and Google Chrome and IE on Windows.

Compatibility

The code is validated as HTML 5. It will first try the HTML 5 playback, and fallback to flash if needed. If neither works, it will display an image showing users that no streaming capability is available and will ask to download the file instead.

  • Firefox 3.5: HTML5-OGG
  • Safari 4 (Mac): HTML5-MP3
  • Safari 4 (PC): HTML5-MP3→Flash
  • iPhone OS 3.1.2: HTML5-MP3 (Small play area due to the lack of the width & height attribute)
  • Opera 10: QT→Flash
  • Chrome 3: HTML5-OGG
  • <= IE 6: Flash
  • >= IE 7: Windows Media Player
Firefox

Firefox

Chrome

Chrome

IE

IE

iPhone

iPhone

Opera

Opera

The Code

<!-- Try HTML 5 playback first. -->
	<audio controls="controls">
	<source src="__AUDIO__.OGG" type="audio/ogg" /> <!-- Firefox and Chrome -->
	<source src="__AUDIO__.MP3" type="audio/mpeg" /> <!-- Safari and iPhone -->

<!-- Windows Media Player class id to enable native streaming on IE 7 and above. IE 6 and below will go straight to flash player -->
	<!--[if gt IE 6]>
	<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="320" height="45"><!
	[endif]-->

	<!--[if !IE]><!-->
	<object type="audio/mpeg" data="__AUDIO__.MP3">
	<!--<![endif]-->

<!-- Windows Media Player controls -->
	<param name="url" value="__AUDIO__.MP3" />
	<param name="autostart" value="false" />
	<param name="uiMode" value="full" />

<!-- Flash fallback -->
	<object height="24" width="320" type="application/x-shockwave-flash" data="__FLASH__.SWF" id="audioplayer">
	<param name="movie" value="__FLASH__.SWF" />
	<param name="FlashVars" value="playerID=audioplayer&amp;soundFile=__AUDIO__.MP3" />

<!-- Fallback image when nothing works -->
	<img class src="__POSTER__.JPG" width="128" height="135" alt="Title" title="No audio playback capabilities, please download the audio below" />

	</object><!--[if gt IE 6]><!-->
	</object><!--<![endif]-->
</audio> 

<!-- Download links outside the audio tag -->
<p>Download Audio: <a href="__AUDIO__.MP3">Audio Format "MP3"</a> | <a href="__AUDIO__.OGG">Audio Format "OGG"</a></p>

The line break in line 8 is due to a bug in IE. I'm not sure if it applies to the audio tag as well, but no harm being safe. A more compact version of the source code follows.

<audio controls="controls">
	<source src="__AUDIO__.OGG" type="audio/ogg" />
	<source src="__AUDIO__.MP3" type="audio/mpeg" />
	<!--[if gt IE 6]>
	<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="320" height="45"><!
	[endif]--><!--[if !IE]><!-->
	<object type="audio/mpeg" data="__AUDIO__.MP3">
	<!--<![endif]-->
	<param name="url" value="__AUDIO__.MP3" />
	<param name="autostart" value="false" />
	<param name="uiMode" value="full" />
	<object height="24" width="320" type="application/x-shockwave-flash" data="__FLASH__.SWF" id="audioplayer">
	<param name="movie" value="__FLASH__.SWF" />
	<param name="FlashVars" value="playerID=audioplayer&amp;soundFile=__AUDIO__.MP3" />
	<img class src="__POSTER__.JPG" width="128" height="135" alt="Title" title="No audio playback capabilities, please download the audio below" />
	</object><!--[if gt IE 6]><!-->
	</object><!--<![endif]-->
</audio> 
<p>Download Audio: <a href="__AUDIO__.MP3">Audio Format "MP3"</a> | <a href="__AUDIO__.OGG">Audio Format "OGG"</a></p>
Usage notes:
  • Replace __AUDIO__.MP3 with the path to your MP3 encoded file
  • Replace __AUDIO__.OGG with the path to your OGG encoded file
  • Replace __FLASH__.SWF with the path to your flash player. I use the standalone version of WordPress Audio Player
  • Replace __POSTER__.JPG with your JPEG image file for fallback purposes

One reason to put the download links outside the audio tag as said by Kroc for his Video for Everybody code: Give people your audio files—you want them to hear the audio anyway and you are fooling yourself if you think that they shouldn’t be allowed to download the audio.

I am not very confident when it comes to writing codes and explaining. In fact I suck at it, so please contact me if you spot any mistakes in my post. Any kind of help to further improve the code is welcomed as well.

Officially Missing You

These 2 Australian-Korean girls have angelic voices. As a matter of fact, I think their singing is better than Tamia's, and I think you would agree too after watching the video. If you like them, you can visit their YouTube channel for more videos.

Before I forget, many thanks to Kroc Camen for his Video For Everybody HTML code. I'll probably talk more about it in later posts. The video plays natively on the iPhone, in Firefox 3.5, Safari 3 & 4 and Google Chrome. On IE, it'll revert to the God awful flash plugin that everyone loves, that is if you have the plugin installed. If not you can just go ahead and download the video.

If you're having problems with playing the video on your iPhone, try refreshing the page a few times or clicking on the direct video link

Download Video: High Quality “MP4” | Low Quality “OGG”

Optimizing Websites

This question has been on my mind for quite some time already: “What makes a website a good website?” Besides that, there are other related questions that I’ve been thinking about too lately; Questions like “Why is it loading so slow?” and “Is it possible to make it load faster?” I’m no expert in anything web related, but I would like to voice out what I think and I hope that my thoughts and suggestions will be helpful to current web designers/developers, as well as those who plan to start making their own websites.

What

For now, I would just like to focus on blogs. Factors that immediately came to mind are:

  • Pictures or cute girls
  • Pictures of hot girls
  • Pictures or wannabe cute girls
  • Pictures of wannabe hot girls
  • Pictures of food (with girls posing)
  • Pictures of uncommon places (with girls posing)
  • Pictures of uncommon objects (with girls posing)
  • Childish writings by cute girls
  • Childish writings by hot girls
  • Childish writings by wannabe cute girls
  • Childish writings by wannabe hot girls
  • Fancy website designs

On the contrary, these are the factors that usually repulse readers from one’s site:

  • Pictures or males
  • Childish writings by males
  • Boring website designs

So as you can see, 7 out of the 12 factors of success I’ve just mentioned consists of pictures with girls in them, and 11 out of 12 of them are related to girls, which is pretty safe to say that pictures and girls are the main source of attraction. I like blogs with pretty pictures of girls too! Abso-fucking-lutely no doubt about that! But althought blogs with pretty pictures are somewhat aesthetically pleasing, they can come at a cost, mainly the cost of losing your readers with crappy connections, especially impatient ones with crappy connections like myself. I can’t remember the number of times I quit my web browser just because a site is taking too long to load.

Why

But occasionally when I do wait until a blog completes loading, I normally find out the reason why it’s taking forever to load just by taking a quick glance at it. These blogs have a plethora of pictures in just a single post, and vary from 5 to 10 posts on the front page. In addition to that, some of them have other fancy features like Flash headers, oversized picture headers, Flash twitter widgets, JavaScript navigational bars, videos and Flash ads to name a few.

A quick benchmark of one of these bloated sites (I shall call it blog-X) show a shocking number of items being loaded:

  • 7 Cascading Style Sheets (CSS)
  • 212 Images
  • 16 JaveScripts
  • 2 application objects

How

Blog-X has a total of 7MB+ of data to be loaded, which is fine if you have a connection of 5Mbps or more. Which means people with shitty connections, mainly Malaysia, with connection speeds that don’t justify their advertised speed of <insert fake speed here>, will suffer, and not to mention delay times and queue times, which adds up to approximately 2-3 minutes of your life drifting away, slowly, waiting for Blog-X to finish loading.

Over the years, i’ve learnt that in web designing, the most important thing to remember is loading time. Try to reduce the number of items your site loads when someone visits it. I like to assume that everyone has a slow connection; It helps to eliminate unnecessary items being loaded, mainly flash and JavaScript objects. Other ways that i’ve learnt are:

  1. Compress Cascading Style Sheets (CSS)
  2. Compress JavaScripts
  3. Optimize images

Referring back to blog-X, 7 style sheets!? Why not just put them all into 1 file? Wouldn’t it be easier to go through 1 file instead of 7 different files to find the CSS property you’re looking for?

And c’mon, 212 images?!? Do you really have to load that many? Change the number of posts that show on your front page! If you know you’re going to write a shit load of trash and upload tons of unoptimized images, then reduced it to a post, or 2 at most. No one wants to wait forever for your site to load while it’s hogging every last drop of connection speed they have. It’s just downright depressing.

Not to forget, 16 JavaScripts, consisting of a few Twitter scripts, a few web counter scripts, and a few more random widget scripts. We don’t need to know how many people visited your site, keep the numbers to yourself. We also don’t need to know when you’re going to bed, when you woke up, what you’re eating or if you’re in the shower or not. These are the type of things that your readers can live without, if not less.

One good compression script for JavaScripts and CSS I found to be very effective and easy to use is Minify. I love how you can combine like files into a single link.

If you’re using WordPress, a possible way of reducing load times is to modify your theme’s single.php file so that it displays a single post per page, while retaining the number of posts shown in your archives per page. The way to do this is to first duplicate your single.php file and rename the duplicated one to home.php. In your index.php file, paste the following code under your get_header(); line.

< ?php $wp_query->is_single = true; ?>

So it should end up looking something like this:

< ?php get_header(); ?>
< ?php $wp_query->is_single = true; ?>

Next is to open up your home.php file and paste the following code under your get_header(); line too.

< ?php
      $i=0; // Initialize to Zero;
      if (have_posts()) :
        while (have_posts()) : the_post();
            if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
        endwhile;
      endif;
      //get only the latest post
      $posts = query_posts( 'p='.$recentpostid."'");
?>

You’re done. Right now your main page should show 1 post per page in the format of single.php.

If you’re wondering why I didn’t just change the reading settings in the admin panel, it’s because if I did, the main page will indeed show 1 post per page, but if I click into my archives, it’ll also show only 1 post per page, which is really annoying if I’m trying to go through my old posts.

When it comes to uploading pictures, I like to first optimize it with Smush.itTM and post thumbnails instead of the full size, which saves on loading time and lets readers have the choice of choosing which picture they prefer to view in full size.

CSS has become so powerful now that it is capable of replacing images. If you’re using Safari 4 or Google Chrome, you should be seeing a blue gradient in my header. It’s done using CSS, not images. Same goes for the calendar on the left of this post. As mentioned in my first post, the only image I’m using for this theme is the “leafy” divider at the end of this post.

Therefore

This article my not be entirely true, but it is based on what I’ve noticed and learnt. Besides methods mentioned above, I’m sure there are other better ones available out there. If anyone would be kind enough to share, please feel free to contact me using the contact form.