how to create a Typing Effect, an Eraser Effect and a Blinking Cursor using jQuery

Typer by Lily-D-Ray on deviantART

First have a look at the demo page (opens in a new tab) to understand what we’re trying to accomplish. You can also download the tutorial’s source code.

For the blinking cursor effect, we’re going to simulate a DOS prompt. The CSS code of the tutorial is very simple. We just have to align all the paragraphs that will include the text parts in one line:

p
{
float: left;
}

The HTML code includes one paragraph that contains the characters “C:\” (the DOS prompt) and another paragraph named cursor that contains the “|” character, our cursor:

<p>C:\</p><p class="cursor">|</p>

To make the cursor blink, we will create a Javascript function named cursorAnimation(). Using jQuery’s animate() function we first make the cursor disappear setting its opacity setting to 0% and then appear again setting its opacity setting to 100%:

function cursorAnimation()
{
  $("p.cursor").animate(
  {
    opacity: 0
  }, "fast", "swing").animate(
  {
    opacity: 1
  }, "fast", "swing");
}

We want this function to run continuously from the loading of the page, so we’re going to use the jQuery’s $(document).ready() function along with the setInterval() method that calls a function at specified intervals (in milliseconds):

$(document).ready(function()
{
  setInterval ( "cursorAnimation()", 600 );
});

Now that we have the blinking cursor we’re going to create the typing effect (based on this tutorial). First, we have to alter our HTML code. We will include a paragraph called caption, a textbox so we can write our preferred caption in there and a button to test the typing effect:

<input type="text" id="userCaption" value="Type something here!" />
<input type="submit" name="submit" value="Test Typing Effect" onclick="testTypingEffect()"/>
<p>C:\</p><p class="caption"></p><p class="cursor">|</p>

First, we define the variables captionLength and caption. When pressed, the button calls the testTypingEffect() function, that sets the textbox’s value to the caption variable and then calls the type() function. The type() function uses the substr() method to cut our preferred caption one letter forward each time it’s called and type it inside the paragraph named caption. Until all the letters of the caption are typed, the type() function calls itself with a delay of 50 milliseconds using the setTimeout() method.

var captionLength = 0;
var caption = "";

function testTypingEffect()
{
  caption = $("input#userCaption").val();
  type();
}

function type()
{
  $('p.caption').html(caption.substr(0, captionLength++));
  if(captionLength < caption.length+1)
  {
    setTimeout("type()", 50);
  }
  else
  {
    captionLength = 0;
    caption = "";
  }
}

For the eraser effect, we will alter again the html code adding another button which when pressed will call the testErasingEffect() function:

<input type="submit" name="submit" value="Test Erasing Effect" onclick="testErasingEffect()"/>

To create the eraser effect, we’ll create the reversed process. The testErasingEffect() function sets the caption paragraph’s content to the caption variable and then computes its length. If there isn’t any content, it types automatically sample content (just for testing reasons) and calls itself. Now that it has a content, it calls the erase() function which cuts letter-by-letter the caption until it’s all gone with a delay of 50 milliseconds.

function testErasingEffect()
{
  caption = $("p.caption").html();
  captionLength = caption.length;
  if (captionLength>0)
  {
    erase();
  }
  else
  {
    $('p.caption').html("You didn't write anything to erase, but ok!");
    setTimeout("testErasingEffect()", 1000);
  }
}

function erase()
{
  $('p.caption').html(caption.substr(0, captionLength--));
  if(captionLength >= 0)
  {
    setTimeout("erase()", 50);
  }
  else
  {
    captionLength = 0;
    caption = "";
  }
}

If you haven’t done it already, have a look at the demo page (opens in a new tab) to test the effects. You can also download the tutorial’s source code.

 

how to create and add a favicon in WordPress using Photoshop

As described in the relevant wikipedia article, a favicon (short for favorite icon, sometimes understood as favorites icon), also known as a website icon, shortcut icon, url icon, or bookmark icon is a 16×16 pixel square icon associated with a particular website. The browsers that provide favicon support typically display a page’s favicon in the browser’s Address bar and next to the page’s title on a tab.

We’re going to create our favicon example, using Photoshop CS3. The favicon needs to be in .ico format and since Photoshop doesn’t have a build-in way of saving an image in .ico format, you have to download this freeware plugin from Telegraphics (supports all versions of Photoshop). After downloading the plugin, you need to place the .8bi file in Photoshop’s plugins folder and restart Photoshop (if already open).

In Photoshop, create a new 16×16 RGB 8-bit image. There is the option to resize an existing image or to create a new one pixel by pixel. As an example, i created pixel by pixel an “E” character using the pencil tool.

favicon example

When you’re done, save the file as favicon.ico and upload it to your root WordPress folder. If you are not using WordPress, upload it wherever you want.

save as .ico

To use it, insert the following code in the head tag of every page that you want to display the favicon. If you are not using WordPress, make sure that the path to the image corresponds to the uploaded directory.

The most common way is

<head>
[...]
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
[...]
</head>

while the W3C way is

<head>
[...]
<link rel="icon"
type="image/png"
href="favicon.ico" />
[...]
<head>

As far as i know, both ways work correct in every browser that displays favicons. Here’s an example of how the example favicon looks on a firefox tab:

favicon@firefox tab

Enjoy!

 

Blackle tells the truth or it is another Urban Legend?

Photo by Habter on deviantART
Photo by ~Habter on deviantART

Early in 2007, Mark Ontkush wrote on his blog that a Black Google Would Save 750 Megawatt-hours a Year. Almost instantly, Blackle appeared among similar projects and soon became the most popular of them. Blackle’s creators are basing Ontkush’s theory on this research paper. Google on the other hand doesn’t seem to agree with the theory, based on this post on its official blog. Blackle and the whole theory have received (as expected) strong criticism. I hope they figure out soon which theory is correct, so i can change my background! :)

In the mean time, take a look at some things you can do now to reduce the energy used by your computer as proposed by the Official Google Blog. It’s on the same article as before, so you don’t have to click again. :P

  • turn on the power management features. Virtually all computers today have the ability to switch into low-power modes automatically when they’re idle; very few computers have this capability enabled! Here’s how to do it on computers running Windows XP.
  • turn off your monitor and computer when you’re not using them
  • turn down the brightness on your monitor
  • make sure your next computer meets the efficiency standards of Climate Savers Computing (an efficient computer uses up to 50% less energy than a conventional one)
  • to find the most efficient PCs available today, look for the words “EnergyStar 4.0 compliant.”