All posts by stoimen

CSS color units

What is a color unit?

By saying CSS units some may guess this is related to the mesurement units. In fact beside the mesurment there is also a color units defined in CSS.

The most used is the #rrggbb, where the three channels red, green and blue are represented with hexadecimals, i.e. #fa03cd, or the short way #rgb. In fact #cc00cc will be the same with #c0c, but #cc02ca is not like #c0c.

Some purple #FA03CD

Actually there are other ways to set a color on an element. Such a way is to set the rgb(255,255,255), which is white. You can easyly transform the hexadecimals to decimals, it’s obvious that xFF is 255 in decimals.

There are five ways to set up a color with CSS

In general there are five ways to set up color with CSS:

#rrggbb ( for red, green and blue as mentioned – #FF00FA )

#rgb ( short way to say #rrggbb – #CC3 )

rgb( x, y, z ) – ( where x, y and z are numbers between 0 and 255 – rgb( 255, 255, 255) )

rgb( x, y, z ) – ( where x, y and z are percents between 0 and 100 – rgb( 100%, 20%, 23%) )

The Windows palette

There is a fift way to set a color on a element with CSS, with predefined colors corresponding to the MS Windows VGA palette, and they are:

aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow

JQuery UI

There is a very good library of UI functionality coming with JQuery, the famous JavaScript library. The UI reference can be found here.

Giving an extream power to use the user interface on it’s limits, with functionalities as drag and drop, resize, select, sort, etc.

This subset of the JQuery library can be used with very small code includes, and that makes the ease of use even more. Actually I think that library is really more easy to use than any other as SPRY, YUI, etc.

I recommend it!

JQuery ajax script call

Many friends are asking me how to they use JQuery AJAX power. However you have two main ways, using:

$(‘#elem’).load(‘url’, ”, function() {});

or

$.ajax({

type : ‘GET’, // or POST

dataType : ‘text’, // or JSON

url : ‘url’,

data : {}, // GET or POST key/value parameters

success : function () {}, // on success callback

error : function () {} // on error callback

});

Note: be careful to miss the comma after the error callback declaration, cause IE is giving some problems with objects with comma after the last key/value pair.

Both methods are useful, but however the second one is more complicated and gives more functionality. It’s important to note that if you’d like to include Html, which will be JavaScript processed after that, there are another two ways. The first one is obvious, you can call the javascript file processing the included Html in your success callback of the first ajax call. After calling the second ajax call, be aware to call it with dataType : ‘script’, which includes de js code and parses it as code. Than you can call whatever function in that .js as you’d do it as it was already included.

That method is obvious and easy, but however on slow nets it’s pretty slow and it’s not useful. Actually you can include your script file as you’d normally do it, with a script tag.

In it you should register all event listeners in methods you can call later. That’s the better way.

In the first case you have:

$.ajax({

type: ‘GET’,

dataType: ‘text’,

url: ‘the_url’,

data: {},

success : function () {

$.ajax({

type: ‘GET’,

dataType: ‘script’,

url : ‘script.js’,

success : function() {

// now do what you want

}

})

},

error : function() {

}

});

In the second case you’d just include your file:

<script src=”script.js”></script>

<script>

$.ajax({

type : ‘GET’,

dataType : ‘text’,

url : ‘url’,

success : function() {

init_script(); // method in script.js

}

});

</script>

Now everything should work OK, good luck!