$fx() – JavaScript Animation Library, Code Samples and Usage

August 21st, 2010

Yesterday I stumbled upon a really awesome Javascript Animation Library: $fx().

This really small (3.4K) super lightweight library gives one the ability to move, resize, or change the color of objects on the screen by using JavaScript to manipulate CSS along a time line. In fact, I believe you can manipulate any CSS property using $fx(). Check out the home page of #fx() for a sample of what $fx() can do and what it can do for you.

I personally don’t know too much JavaScript, I just never got into it….until last night that is. One of the problems I had with the $fx() website was that their code samples were just javascript and I didn’t know how to execute the javascript commands in my pages very precisely. I proceeded to check out their home page, understood what their page did, strip out all but one cloud in the HTML and JS files, saved it and observed. I would like to share with you some full working examples of$fx() to help you get started using it ASAP, it really is simple and efficient if you know how to use it!

Here we will move an image of a cloud from right to left forever. When you setup this working example on your computer or project server you will need to create an images folder and place an image named cloud1.png in it, then go to http://fx.inetcat.com/ and download the fx.js library. (If their site is down or something, download my copy of $fx() Javascript Animation Library).

(Download a working example of $fx() Javascript Animation Library)

Index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>$fx() - JavaScript Animation Library</title>
<link href="style.css" rel="stylesheet" />
<style type="text/css">
#john{
background-image:url(images/cloud1.png);
width:100%;
height:800px;
background-repeat:no-repeat;
}
</style>

<script src="fx.js"></script>
<script type="text/javascript">
var ani = {
gross1: {type: 'backgroundx', from:screen.availWidth,to: -600, step: -5, delay: 10},
};

function startAnimation(){
$fx('#john').fxAdd(ani.gross1).fxRun(null, -1);
}
</script>
</head>
<body onload="startAnimation();">
<div id="john">Text</div>
</body>
</html>

When the page loads, the body tag calls startAnimation(); which is where the code is executed. The javascript array ani contains entry gross1, which holds the actual commands that $fx() will run. See below:


var ani = {
varname: {type: 'css-attribute', from:screen.availWidth, to: -600, step: -5, delay: 10},
};

function startAnimation(){
$fx('#divid').fxAdd(ani.varname).fxRun(null, -1);
}

Here we can see one effect being ran, but let’s say we wanted to also change the font size of the text as well:


<script type="text/javascript">
var ani = {
gross1: {type: 'backgroundx', from:screen.availWidth,to: -600, step: -5, delay: 10},
gross2: {type: 'fontSize', from:10,to: 200, step: 2, delay: 5},
};

function startAnimation(){
$fx('#john').fxAdd(ani.gross1).fxRun(null, -1);
$fx('#john').fxAdd(ani.gross2).fxRun(null, -1);
}
</script>

So what else can you change with $fx()? Well I think the $fx() site explains that pretty clearly:

fxAdd()
fxAdd(params) — adds a new effect to the current set. The effects wont run immediately, but will be added to your animation set. The entire set will run after the fxRun() call is made.

params object sets animation parameters. Required set of fields to be defined:

  1. type — type of animation effect. The type parameter is same as the CSS property name for a DOM element. So, to alter the X-Coordinate of an element, the type needs to be set to ‘left’. Other properties you can alter are:

    opacity — cross-browser property to adjust an element’s opacity.
    backgroundx — background X position.
    backgroundy — background Y position.

  2. from — initial value for property defined in type. This parameter is optional. If it hasn’t been defined then property will be retrieved from style property (style=”property:value”). If style property is not defined in HTML then effect won’t be applied because of insufficient parameters (an animation needs a starting point!). Some methods have special needs: Opacity attempts to get value from element.style.filter in Internet Explorer and reads element.style.opacity property for all other browsers. Backgroundx and backgroundy retrieves values from element.style.backgroundPosition. Left, top, width and height aren’t retrieved from style properties, so it’s not necessary to define left, top, width, or height in the element’s style attribute.
  3. to — end property value. Once it has been reached, the effect stops running.
  4. step — positive or negative integer value to alter a CSS property, per one iteration (i.e. step).
  5. delay — delay between iterations in milliseconds. This parameter is optional, by default it is 100. Do not set this number too high, unless you want choppy animation.
  6. unit — optional parameter to define measurement units for a certain CSS property. If unit wasn’t defined, then it will be picked by type value: left, top, right, bottom, width, height, margin, padding, spacing, backgroundx, backgroundy – px; font – pt; no unit for all other properties.
  7. onstart — function called before effect starts. You can use this object inside callback, which references to the element.
  8. onfinish — same callback as onstart but runs after affect is complete.

All in all, $fx() is a great tool for web developers who need to get some animation done fast, simple, lightweight and no BS.

Maybe go donate to them if you can…

The DISCLOSE Act HR 5175

August 19th, 2010

A new bill is about the change the face of politics forever. The “Democracy is Strengthened by Casting Light on Spending in Elections Act” or the DISCLOSE Act, should be renamed the “Stifling Grassroots Political Support and Removing Political Privacy Bill”. This act affects all people and organizations. It is an attempt to silence gun rights groups from talking about the voting history of our politicians. They even have special exclusions so for some organizations …it’s aim is to silence the pro gun groups because they appose Hairy Reed. It is a sickening attempt at taking away our rights while trying to stop groups from talking politics, and right before the upcoming elections no the less.

I think Harry Reed should be arrested for fraud. That’s right. Because with his DISCLSOE act HR 5175, he is intending to deceive all of us for a selfish personal agenda.

…I hope Ron Paul runs for president again someday….

Shale Gas, A source of natural gas

August 19th, 2010

Shale gas is natural gas produced from shale. Shale gas has become an increasingly important source of natural gas in the United States over the past decade, and interest has spread to potential gas shales in Canada, Europe, Asia, and Australia. One analyst expects shale gas to supply as much as half the natural gas production in North America by 2020.

Some analysts expect that shale gas will greatly expand worldwide energy supply.[2] A study by the Baker Institute of Public Policy at Rice University concluded that increased shale gas production in the US and Canada could help prevent Russia and Persian Gulf countries from dictating higher prices for the gas it exports to European countries.[3] The Obama administration in the US believes that increased shale gas development will help reduce greenhouse gas emissions.[4]

Because shales ordinarily have insufficient permeability to allow significant fluid flow to a well bore, most shales are not commercial sources of natural gas. Shale gas is one of a number of “unconventional” sources of natural gas; other unconventional sources of natural gas include coalbed methane, tight sandstones, and methane hydrates. Shale gas areas are often known as resource plays[5] (as opposed to exploration plays). The geological risk of not finding gas is low in resource plays, but the potential profits per successful well are usually also lower.

Shale has low matrix permeability, so gas production in commercial quantities requires fractures to provide permeability. Shale gas has been produced for years from shales with natural fractures; the shale gas boom in recent years has been due to modern technology in hydraulic fracturing to create extensive artificial fractures around well bores.

Horizontal drilling is often used with shale gas wells, with lateral lengths up to 10,000 feet within the shale, to create maximum borehole surface area in contact with the shale.

Shales that host economic quantities of gas have a number of common properties. They are rich in organic material (0.5% to 25%), and are usually mature petroleum source rocks in the thermogenic gas window, where high heat and pressure have converted petroleum to natural gas. They are sufficiently brittle and rigid enough to maintain open fractures. In some areas, shale intervals with high natural gamma radiation are the most productive, as high gamma radiation is often correlated with high organic carbon content.

Some of the gas produced is held in natural fractures, some in pore spaces, and some is adsorbed onto the organic material. The gas in the fractures is produced immediately; the gas adsorbed onto organic material is released as the formation pressure is drawn down by the well.

Just thought this was interesting and wanted to share!

Check out other video on Shale Gas!