InteractiveVolcano

An all-inclusive interactive and creative website providing tutorials for Javascript, Flash + jQuery.
So get started by delving into one of our tutorials today.

jQuery? You’ve got to toggle

jQuery?  You’ve got to toggle

Toggling makes it easy to turn things on and off

Everyone likes writing jQuery for one main reason: it’s really easy to use. One feature that makes life a lot easier is toggling. Let’s say you have an image that you need to show when a button is clicked and then hide when it is clicked again. Instead of two separate functions, one to show and another to hide, use jQuery’s handy shorthand: toggle:

$(‘button’).click( function() {
$(this).toggle();
});

But jQuery’s support of toggling goes way beyond hiding and showing. It has toggleClass() which adds a class or removes it depending on if the class exists. Also slideToggle() which slides an object up and then down.

And besides these simple shorthands for existing functions, jQuery has a variety of support for more custom toggle functions. … (more…)

Appending Grayed-Out Overlays with jQuery and CSS

Grayed-out overlay example

Probably one of the most widely adopted “web 2.0” features is the grayed out overlay. Rather than always redirecting users to a new page, overlays allow the current page to get “grayed out” with an overlaid panel. With the wide use of Javascript libraries like jQuery, the prevalence of these grayed-out overlays is understandable: they are very easy to build.

Let’s start with the markup and CSS. We’ll need two wrappers, appended at the end of the DOM. Although we will append these later with jQuery, for now just put them right in the HTML (or wait until we append them).

The idea for these wrappers is that the first ‘overlay’ div will be the grayed-out background and the ‘overlay-panel’ will be the HTML panel that sits on top of the overlay.

Now let’s get started by styling the overlay. The first problem we’ll have to tackle … (more…)

Best Practices: How to Include IE-Specific CSS Styles and Stylesheets

IE specific CSS stylesheets

Although good CSS should be written to be as browser-universal as possible, even the best front end developers find it necessary at times to target specific browsers for certain styles. In most cases this means writing a set of special CSS blocks to handle eccentricities in IE and its various versions.

There’s a wide variety of reasons to target specific browsers: IE6’s lack of native support for transparent png24’s, pesky ‘has-layout’ bugs, and IE6’s lack of min-height support are just a few.

One way to target specific browsers is through CSS selector hacks, which take advantage of quirks in different browser implementations. Perhaps the best known browser hack is the “star html” hack. Basically you prepend * html to any normal selectors in order to target IE6 specifically:

Controlling Animation Timing in jQuery

Timing animations in jQuery can appear confusing

Animation and function timing can often seem like an uphill battle in Javascript. Thankfully jQuery’s variety of timing control mechanisms provide excellent alternatives to Javascript’s standard order of function processing.

With both callback functions and chainable methods, jQuery allows much greater control over animation timing than Javascript alone. Callback functions provide the ability to execute a function once an animation has completed. Chainable methods allow us to stack a series of operations on a single object. Combining the two, jQuery provides near perfect control over the timing of animations.

Build a Simple Flash MP3 Player in AS2

Making a MP3 player is really simple using Flash and AS2. First open up an FLA in Actionscript 2.0 format. In the first frame, open the actions window and write:

var simple_mp3:Sound = new Sound();
simple_mp3.loadSound( ‘example.mp3’, true );

Here we’re loading the MP3 ‘example.mp3’. The second variable in loadSound() is whether to stream the media. If you would like to wait until the MP3 loads completely, just set this to false.

Supporting the Browser Back Button with Javascript

How to support the browser back button

When developing a Javascript-heavy, AJAX-riddled site, I often run into a 2.0 type of problem: supporting the browser back button. While it’s wonderful to build a site where users are brought to various content pages without the window refreshing, this excellent user experience will be completely ruined if you hit the back button and it returns you to the root of the site (or worse the last site you visited).

Thus, integrating the browser becomes an integral part of any Javascript developer’s toolkit.

Making the browser recognize Javascript changes

The first problem we have to solve is making the browser respect a Javascript change as a page change. However we have to be sure not to change the actual location of the page, or our AJAX or Javascript experience will be shot.

One thing to look at is the window location’s … (more…)

Make a Javascript Clock

Although there are many ways to make a clock using Javascript, most use Javascript’s date() object and the setInterval() method. In this tutorial we’ll start by building a clock using these simple functions. Then we’ll explore some interesting ways of optimizing our clock, and hopefully learn a whole bunch of Javascript along the way.

Getting the current time

Let’s kick things off by getting the current time with Javascript. To do so, we will need the Javascript date() object. Remember that this gets the client-side time, e.g. the time in the user’s browser, not the actual time on the server. Client-side time is great for situations like ours, since it takes away any time-zone localization problems.

The date() object is simple enough to use, just instantiate it:

var d = new Date();

Then you can call any properties of this object, getMinutes(), getDay(), getDate(), etc. … (more…)

A Javascript Event Handler Script

Do you remember the dark days of HTML? A million inline properties that were a nightmare to handle even on the smallest websites. Thankfully CSS came along, and good developers now control most of their styling through a centralized stylesheet.

So why shouldn’t we do the same thing with Javascript? A bunch of inline events all over the document with onclick=”” or onmouseover=”” is just as bad as inline styles or font-tags.

However, attaching these event listeners from a central Javascript poses a challenge, since the listener implementation differs from browser to browser. While there are a lot of scripts to attach event listeners, in 2001 Scott Andrew came up with an excellent cross-browser event handler script.

For our Javascript code-library, we’ll use a modification of it:

function addEvent(obj, evType, fn){
if (obj.addEventListener){
(more…)

A Leading Zeros Function

Although Javascript has an excellent method for attaching trailing zeros to decimals, there is no native function to attach leading zeros. For example, if you are dealing in currency, and want ten cents to appear as .10, instead of .1, you would just write:

var theNumber = .1;
theNumber = theNumber.toFixed(2);

Javascript’s toFixed() is great for trailing zeros, but what if you wanted a fixed number of leading zeros? If you wanted 10 to display as 0010?

A leading zeros function is handy tool in any Javascript library, so let’s write one now. We’ll need two variables: a number to format and the number of digits. We’ll change the number into a string, then attach leading zeros (more…)

Hacking sIFR 2’s Font Replacement

sIFR 2

With sIFR 3 still in beta, let’s explore hacking sIFR 2 to behave with more of today’s Flash functionality.

To get started, download sIFR 2. A common complaint about sIFR font replacement is that the fonts look too pixelated or light. A quick trick to fixing this is to up the Flash version from 6 to 8. Edit “sifr.js” on line 7 change “var a=6” to “var a=8” so that we’re detecting for version 8. The fonts won’t look perfect, but they will be noticeably better.

Next, we can add letter-spacing functionality to sIFR. Open up “dont_customize_me.as” (don’t worry) and place this at line 92:

if (letterSpacing != null) fmt.letterSpacing = Number(letterSpacing);

With this technique we control the letter spacing using flash vars:

sFlashVars:”otherflashvar=true&letterSpacing=2″

Finally, when you publish, make sure to export it for Flash version 8 with ActionScript 2.0. … (more…)