Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Saturday, August 15, 2009

Practical solutions to hyphenate text on web pages

In this post I want to suggest you three simple and useful ways to hyphenate text on your web pages using JavaScript or PHP. If you take a look at W3.org documentation you can find this explanation about hyphenation:

"In HTML, there are two types of hyphens: the plain hyphen and the soft hyphen. The plain hyphen should be interpreted by a user agent as just another character. The soft hyphen tells the user agent where a line break can occur. Those browsers that interpret soft hyphens must observe the following semantics: If a line is broken at a soft hyphen, a hyphen character must be displayed at the end of the first line. If a line is not broken at a soft hyphen, the user agent must not display a hyphen character. For operations such as searching and sorting, the soft hyphen should always be ignored."

To hyphenate text I found the following practical solutions:

Hyphenator.js
This script automatically hyphenates texts on websites and runs on any modern browser that supports JavaScript and the soft hyphen (­). It runs on the client in order that the HTML source of the website may be served clean and svelte and that it can respond to text resizings by the user. The result is really great:



The usage of this script is really simple. You have to include the script into your pages in the <head> tag:

<script src="hyphenator.js" type="text/javascript"></script>

...then you have to invoke the script adding this code after the previous code:

<script type="text/javascript">
Hyphenator.run();
</script>

...and use this HTML code to active hyphenation:

<p class="hyphenate text" lang="en">
Your text here...
</p>

Take a look at this example for a live preview.

You can also choose the language changing the property "lang" (actually the script support 16 languages, for the full list take a look here).


phpHyphenator
The phpHyphenator is a PHP port of the JavaScript hyphenator.js by Mathias Nater for automatic hyphenation in web pages using soft hyphens. The hyphenation algorithm needs large pattern files for doing the hyphenation and and using JavaScript can slow down page loading. PHP instead is doing hyphenation directly on the server wihtout sending the pattern files to the client.


Online Soft Hyphenation Generator
You can also try this interesting on-line HTML Soft Hyphenation Generator a configurable automatic hyphenation (soft or hard) generator for HTML text based on phpHypenator.




Any suggestion about this topic? Please leave a comment, thanks!

Friday, August 14, 2009

CSS3 rounded corners for every browser? An alternative quick solution without headache

In the last weeks I frequently received a question about how to use CSS3 border-radius property to draw HTML elements with rounded corners in Internet Explorer. How you know CSS3 border-radius property is natively supported in Safari, Firefox and Chrome but for some mysterious reason this property is not supported in Internet Explorer.

So to draw rounded corners in IE you have to use some trick, for example using CSS classes with a background image (take a look at this post).


The simpler and quick solution I know to draw rounded corners in every browser is to use a mix of CSS3 and JavaScript. CurvyCorners is a free JavaScript library for creating gorgeous rounded corners for HTML elements. The final result looks like this:



The big advantage of this script is that lets render rounded borders in Safari, Chrome and Mozilla (which support rounded borders via -webkit-border-radius and -moz-border-radius) natively with CSS3 property and in IE and Opera with JavaScript.

The only thing you have to do is to include curvycorners.js into the <head> tag of your page:

<script type="text/javascript" src="curvycorners.js"></script>

Then you have to write a CSS class like this:

.roundedCorners{
width: 220px;
padding: 10px;
background-color: #DDEEF6;
border:1px solid #DDEEF6;

/* Do rounding (native in Safari, Firefox and Chrome) */
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
}

At this point add the following code into the <head> of your page, after the previous CSS code:

<script type="text/JavaScript">
addEvent(window, 'load', initCorners);
function initCorners() {
var setting = {
tl: { radius: 6 },
tr: { radius: 6 },
bl: { radius: 6 },
br: { radius: 6 },
antiAlias: true
}
curvyCorners(setting, ".roundedCorners");
}
</script>


tl, tr, bl, br are: top-left, top-right, bottom-left, bottom-right borders.

If you have different CSS classes (ex. roundedCorners, roundedCorners_1, roundedCorners_2) you can apply them changing the previous code in this way:

...
curvyCorners(setting, ".roundedCorners");
curvyCorners(setting, ".roundedCorners_1");
curvyCorners(setting, ".roundedCorners_2");
...


Now if you want to apply rounded corners to a DIV element use this code:

<div class="roundedCorners"> </div>

This is the result in every browser:


I think this is actually the simpler and quick solution to implement rounded corners in every browser. Ok... and what's if JavaScript is disabled? Sincerly I think this case is not so frequent... but if you don't want to use JavaScript, the most realiable solution is to use CSS classes with background images. Any suggestion about this topic? Please leave a comment, thanks!

Download the source code here:




 
Liquid styled input element with CSSClean Tab Bar Digg-like using CSSLiquid expandable section with rounded corners using CSSLiquid layer with rounded corners using css

Sunday, February 8, 2009

Ultra small code to drag everything in HTML pages

A frequent question I receive from my readers is about how to implement a simple script to drag elements in a web page. So in this post I want to illustrate the simplest method I know and use to drag everything in HTML pages, using just three rows of Javascript code.

In this post I provided a very basic script quick to reuse and customize in your web projects (in the live preview I added some little additional features respect the content of this tutorial). This is the result:


Download this tutorial Live preview



HTML code: HTML code is very simple. You have to add a main layer with an ID (I used "draggables") and some DIV layers inside that layer. In this way all layers contained inside the layer "draggables" will be draggable when you select them. This is the structure:



Copy and paste this code in your page:

<div id="draggables">
<div>
Some content Here...</div>
<div>Some content Here...</div>
<div>Some content Here...</div>
</div>


JavaScript code: Now take a look at this simple code which enable drag features. Before all add a link to MooTools farmework in the <head> tag of the page:

<script type="text/javascript" src="mootools.svn.js">
</script>

Now, copy and paste this simple unobtrusive code:

<script type="text/javascript">
window.addEvent('domready', function(){
$('#draggables div').each(function(drag){
new Drag.Move(drag);});
});
</script>

Simple no? Just in three rows! In this way when you click on a div element contained inside the layer #draggables it will be draggable. In this tutorial I used DIV layers for my draggable elements but you can use every tag you want (p, h1, h2, ul, li....). The only thing you have to change is HTML code and DIV - with the tag you use (p, h1, h2, ul, li....) - in this line:

$('#draggables div').each(function(drag)


You can also add a custom style to your draggable elements using a simple CSS class I called "drag". For example, change the previous code HTML with the following:

<div id="draggables">
<div class="drag"
>Some content Here...</div>
<div class="drag">Some content Here...</div>
<div class="drag">Some content Here...</div>
</div>

...and CSS code could be something like this:

.drag{
border:solid 6px #DEDEDE;
background:#FFF;
width:200px;
height:150px;
...
}

That's all! Try it and download the source code ready to use in your porject.

Download this tutorial Live preview

Tuesday, January 20, 2009

Ultra versatile slider for websites

After my previous post about the Art of reusing code in your web projects I received many messages which asked to me to release an improved version of the slider I illustrated in the example number 3 of that post.

So, in this tutorial I'll explain a simple step-by-step way to implement an ultra versatile slider with horizontal scrolling and animated effects using MooTools. This is a basic proposal you can improve how you prefer. I included a link to the source code you can customize and reuse quickly in your web projects. The result is something like this:



Take a look at the live preview and download the source code.



Download the source code Live preview


HTML structure
HTML structure is very simple. We need a layer (DIV) and a simple list (UL). First step:create a layer which is the container of slider content:


Add this code:

<div id="slider-stage">
</div>

Simply, no? Now you have to add some elements (boxes) into that container using a simple <ul> list and some <li> elements. You have to set #slider-stage width to a certain value (for example 600px) and use owerflow property to create a "mask" like the following:



In this way you have a visible area and an invisible area. To set overflow property take a look at the next step which defines CSS properties. So...this is the code for the list:

<div id="slider-stage">
<ul id=
"myList">
<li >Box 1</li>
<li >Box 2</li>
<li >Box 3</li>
<li >Box 4</li>
<li >Box 5</li>
<li >Box 6</li>
</ul>
</div>


You can add all boxes you want simply adding a new <li> element in the previous code. Within each <li> element you can add all you want (text, images, videos...)
Now, after the previous code, add buttons to slide content to left or right using this code:

<div id="slider-buttons">
<a href="#" id="previous">Previous</a> | <a href="#" id="next">Next</a&gt;
</div>

Make attention do not change the name of buttons ID property (previous and next)!


CSS Code
Now take a look at CSS code. How I said you have to use overflow property to create a "layer mask" and hide all content (list elements) external to the container #slider-stage. More over take a mind this in order to set #slider-stage width:



If you have 3 visible boxes in your slider to set #slider-stage width you have to consider the box widht, padding and margin-left. So, #slider-stage width will be:

(box width * 3) + (box padding*3) + (box margin-right *2)

In the following case #slider-stage width is 632px (200*3 + 4*2*3 + 4*2):

#slider-stage{
width:632px;
overflow:auto;
overflow-x:hidden;
overflow-y:hidden;
height:200px;
margin:0 auto;
}
#slider-list{
width:2000px;
border:0;
margin:0;
padding:0;
left:400px;
}
#slider-list li{
list-style:none;
margin:0;
padding:0;
border:0;
margin-right:4px;
padding:4px;
background:#DEDEDE;
float:left;
width:200px;
height:200px;
}


JavaScript Code
Now, take a look at this simple script to enable slider features. I used MooTools to implement this script so, you have to add this link into the <head> tag of the page where you want to use this slider:

<script type="text/javascript" src="mootools.svn.js">
</script>

Now, copy and paste this code below the previous line of code to enable scrolling features (you can also copy this file in an external Js file and import it into the page):

<script type="text/javascript">
window.addEvent('domready', function(){
// Declaring increment vars
var totIncrement = 0;
var increment = 212;
var maxRightIncrement = increment*(-6);
// FX var
var fx = new Fx.Style('slider-list', 'margin-left', {
duration: 500,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});

// Previous Button
$('previous').addEvents({
'click' : function(event){
if(totIncrement<0){
totIncrement = totIncrement + increment;
fx.stop()
fx.start(totIncrement);
}
});

// Next Button
$('next').addEvents({
'click' : function(event){
if(totIncrement>maxRightIncrement){
totIncrement = totIncrement - increment;
fx.stop()
fx.start(totIncrement);
}
}
})
});
</script>

If you have some familiarity with MooTools and JavaScript it will be very simple to understand:

var increment = 212;

...is the horizontal increment when you click the button previous or next. It's equal to the width of <li> element (200px) + padding (left + right = 4px+4px = 8px) + margin-right (4px).

var maxRightIncrement = increment*(-6);

...is the maximum increment from left to right. Why (-6)? Because I added 9 elements into the slider; default view display 3 elements each time; so to reach the element 9 you have to press the button "next" 6 times! Naturally you have to change this value if you change the number of <li> elements.

It's all! Take a look at the live preview or download the source code ready to use in your web porojects! Add a comment or send me a message if you have problems to implement it.

Download the source code Live preview

Thursday, January 1, 2009

Nice vertical menu with motion and opacity effect

In this tutorial I explain how to design a vertical menu which use motion and change opacity effect. I wrote this post to show a better use of elastic effect which I illustrated in my latest post.

The effect I want to realize is the following. I have a vertical menu with some links. On "mouse over" the select link goes to the right with an animated elastic effect and change its opacity. When you release the element, it goes in its initial position with original opacity value. The result is something like this:



Take a look at the live preview to see this script in action.


Download source code Live Preview


HTML code
HTML code is very simple. We have a list (<ul>) with some <li> elements with a progressive ID (l1, l2, l3, l4...):

<ul id="menu">
<li id="l1"><a href="#">About</a></li>
<li id="l2"><a href="#">My Facebook Profile</a></li>
<li id="l3"><a href="#">Tutorials</a></li>
<li id="l4"><a href="#">My Book</a></li>
<li id="l5"><a href="#">Download</a></li>
<li id="l6"><a href="#">Contact</a></li>
</ul>


CSS code
I used this simple CSS code to set the look of links but you can customize it how your prefer:

#menu li{
list-style:none;
margin:0;
padding:0;
border:0;
margin-bottom:2px;
}
#menu li a{display:block;
padding
:4px;
background
:#DEDEDE;
text-decoration:none;
}

JavaScript code
In order to obtain our effects (elastic motion + change opacity) I used MooTools framework and some lines of Js code. In the <head> tag of the page add a link to MooTools:

<script type="text/javascript" src="mootools.svn.js"> </script>


Now, copy and paste this code below the previous line of code in the <head> tag of the page (if you prefer you can also copy this code in a separated .js file and import it in your page):


<script type="text/javascript">
window.addEvent('domready', function(){
$('#container div').each(function(item){
var o = item.id

// FX motion with elastic effect
var fx-motion = new Fx.Style(o, 'margin-top', {
duration: 1000,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});

// FX opacity effect
var fx-opacity = new Fx.Style(o, 'opacity', {
duration: 1000,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});
item.addEvents({
'mouseenter' : function(e){
fx-motion.stop()
fx-opacity.stop()
fx-motion.start(0,100);
fx-opacity.start(0.5);
},
'mouseleave' : function(e){
fx-motion.stop()
fx-opacity.stop()
fx-motion.start(0);
fx-opacity.start(1);
}
});
})
});
</script>

It's all! Download the source code and send your suggests!

Download source code Live Preview

Related Post
Super elastic effect to design high impact web menu

Wednesday, December 31, 2008

Super elastic effect to design high impact web menu

This tutorial explais how to design an high impact elastic effect to make original web menu using some lines of Javascript code and MooTools framework. The effect is simple to develope and reuse in your web projects changing only HTML code and CSS. Take a look!

The effect I want to realize is the following. I have a "layer cloud" with some layer overlapped to the others. On "mouse over" the select layer goes down with a nice animation effect and when you release the element this goes up with an elastic effect:


Take a look at this live preview to see this script in action.


Download source code Live Preview


1. HTML code
Create a layer which contains all elements in the "cloud" (in this case I used DIV elements):

<div id="container">
<div id="contact">This is the layer about me.</div>
<div id="about">Contact me? <a href="mailto:myemail@email.com">My Email</a></div>
<div id="profile">This is my <a href="http://woork.blogspot.com">website</a></div>
</div>


2. CSS Code
Use CSS to stylize previous elements how you prefer. In this tutorial I used this CSS code:

#about {
width: 200px;
padding: 8px;
background: #DEDEDE;
color: #333;
position: absolute;
z-index: 1;
left: 31px;
top: 66px;
border:solid 4px #CCC;
}

#about {
width: 200px;
padding: 8px;
background: #DEDEDE;
color: #333;
position: absolute;
z-index: 1;
left: 80px;
top: 37px;
border:solid 4px #CCC;
}
...

The result is something like this, a "layer cloud" with some layer overlapped to others:




You can add other overlapped layers simply adding new <div> elements in step (1) with the related CSS stlye in step 2. To overlap layer I use CSS properties "position:absolute" and "z-index" for each element.


3. JavaScript code
In order to obtain our elastic effect I used MooTools framework and some lines of Js code.
No fear... it's very simple! In the <head> tag of the page add a link to MooTools:

<script type="text/javascript" src="mootools.svn.js"> </script>


Now, copy and paste this code below the previous line of code in the <head> tag of the page (if you prefer you can also copy this code in a separated .js file and import it in your page):

<script type="text/javascript">
window.addEvent('domready', function(){
var zindex = 2;
$('#container div').each(function(item){
var o = item.id
var fx = new Fx.Style(o, 'margin-top', {
duration: 1000,
transition: Fx.Transitions.Back.easeInOut,
wait: true
});
item.addEvents({
'mouseenter' : function(e){
fx.stop()
fx.start(0,100);
zindex = zindex + 1;
$(o).setStyle('z-index', zindex)
},
'mouseleave' : function(e){
fx.stop()
fx.start(0);
zindex = zindex - 1;
$(o).setStyle('z-index', zindex)
}
});
})
});
</script>

In this code I used a MooTools basic knowledge. In the past week I already dedicated several lessons about that. I suggest you to take a look at these post:


Download source code Live Preview

It's all! Do you have some suggest? Add a comment!

Monday, August 25, 2008

Design a stunning Alert Box using MooTools

Do you want to change the default style of JavaScript Alert Box? Do you want to add a nice animation with MooTools? Take a look at this post!

About the Author

Eduardo Sada
Programmer and Web Designer
Coders.me

The Script

This tutorial explains how to design a stunning Alert Box which changes and improves the classic look of JavaScript Alert Boxes.



The result is something like these you can see in the previous picture. Alert box appears on the page, above all other page elements with a nice animation. Try it!

Download source code Take a look here for a live preview


1. How to install this script
Downloading the package you have all do you need to use this nice script. First of all, add a link to MooTools Framework and to sexyalertbox.js within the <head> tag of the page in this way:

<script src="mootools.js" type="text/javascript"></script>
<script src="sexyalertbox.v1.js" type="text/javascript"></script>

...then add this link to the CSS file:

<link rel="stylesheet" href="sexyalertbox.css" type="text/css" media="all" />

...and if you want to change the default look of Alert Box you can customize the CSS file how you prefer.

2. HTML Code
Add this line of code within the <body> tag:

<script type="text/javascript">
window.addEvent('domready', function() {
Sexy = new SexyAlertBox();
});
</script>

...and for example create a link which display an alert box with a simple message "Nice!":

<a href="#" onclick="Sexy.alert('Nice!'); return false;">Show a JavaScript alert with a new look!</a>


In this way when an user click on this link an alert box will appear above all other elements of the page. It's all! For other info, please take a look at the documentation you can find at this link.

Related Post
MooTools - Basic Tips for Web Designer
MooTools - Get elements ID using unobtrusive code

Saturday, August 23, 2008

MooTools Basic Tips (lesson 2): get elements ID using unobtrusive code

After my previous post about MooTools Basic Tips for web designer I received a lot of excited messages from my readers, lovers of this beautiful framework, for this session of lessons dedicated to MooTools. Thanks a lot guys! I really appreciate your support! So... a question which a lot of peopole asked to me was how it's possible to get the ID of an element (for example the ID of an element into a list) and associate to this element some event (change background, display an alert message...). In this post I want to illustrate how to get the ID of DOM elements using MooTools and unobtrusive elegant code.


1. An "Obtrusive" way to implement it
Before to explain how to do it with MooTools, I think it's better take a look at the following HTML code:

<ul id="myList">
<li id="li_1">
<a href=
"#" onClick="javascript:getId('1')">Get this ID</a>
</li>

<li id="li_2">
<a href="#" onClick="javascript:getId(2)">Get this ID</a>
</li>

<li id="li_3">
<a href=
"#" onClick="javascript:getId(3)">Get this ID</a>
</li>

</ul>


This is a simple list with some list elements with id "li_1", "li_2", "li_3". Each list element contains within a link which calls, with an event onClik, a Javascript function getId(). This function takes in input the number related to the list element ID, within which the link is contained, displaying a simple alert window with the ID of the element you've chosed. The result is something like this:



Javascript code is something like the following:

<script type="text/javascript">
function getId(el){
var listElement = el;
alert("The ID of the list element you've chosen is: li_"+listElement);
}
</script>

...it's simple and clear if you have basic javascript notions. But why this code is obtrusive?. Because, withing HTML code, it contains a call to the JavaScript function getId():

<a href="#" onClick="javascript:getId('1')">Get this ID</a>

It's not wrong. But it's better to separate HTML code from JavaScript code. How you can do it? Read more...


2. The unobtrusive way to implement it using MooTools
Ok, now we are ready to see how we can implement the same script using unobtrusive code with MooTools. First, take a look at the HTML code:

<ul id="myList">
<li id="li_1"><a href="#">Get this ID</a></li>
<li id="li_2"><a href="#">Get this ID</a></li>
<li id="li_3"><a href="#">Get this ID</a></li>
</ul>


What's changed from the step 1? I removed onClick event within each link:

<li id="li_1"><a href="#" onClick="javascript:getId('1')" >Get this ID</a></li>

Than, how changes JavaScript code to get the ID of the element? First, remember to add a link to MooTools framework in the <head> tag of the page:



Copy and paste the following code within the <head> tag:

<script type="text/javascript" src="mootools.svn.js"></script>

... and now copy, below the previous code, the following:

<script type="text/javascript">
window.addEvent('load', function(){
$('myList').getElements('li').each(function(el){
el.getElement('a').addEvent('click', function(listID){
alert("The ID of the list element you've chosen is: "+listID);
}.pass(el.id)
);
});
});
</script>

How you can see, I used getElements() method to get all <li> tags within <ul> list with ID "myList ". Every times you click on <a> element contained into a <li> tag, the function display an alert window with the ID of the element you've chosed, passing the ID using .pass(el.id) method. It's all and it's very simple!

Take a look at the source code:

Download source code

Add a comment for other info or request!


Related Content
MooTools Basic Tips for Web Designer (Lesson 1)

Thursday, August 21, 2008

MooTools Basic Tips for Web Designer (Lesson 1)

After a lot of requests, in this article I want to illustrate some simple tips to start to work with MooTools. In this first lesson you can see how to manipulate element properties, in particular how to get DOM element by ID, how to use getStyle(), setStyle() (to get and set CSS properties), toInt() to convert string to number and some examples to introduce how to write unobtrusive JavaScript code with MooTools.


1. Add Mootols framework to your page
First, you have to download the latest version of MooTools and add a link to the framework within the <head> tag of the page:




Copy and paste the following code within the <head> tag:

<script type="text/javascript" src="mootools.svn.js"></script>

Ok, now you are ready to use MooTools feautures in your web pages!


2. Get DOM element
To get a DOM element by ID you can use the following syntax:

var element = $('myElement');

... this line of code gets the element with ID="myElement" in your page. If you have some falimiarity with JavaScript, it's almost the same thing to get a DOM element by reference using the following code:

var element = document.getElementById('myElement');

Ok, now using $$ you can get an array of elements within a DOM element with a specific ID:

$$('#myElement li.myListElement');

...for example, this line if code returns an array of all <li> tags with the class="myListElement" within the DOM element with ID="myElement".


3. setStyle() and get Style()
These are two basic methods to set and get element properties (height, background, color...). To set a property you can use the following code:

$("myElement").setStyle("height", "200px")

...or if you have to set multiple properties you have to use the following code:

$("myElement").setStyles({
background: "#DEDEDE",
border:"solid 1px #999999",
width: "700px"
height: "80px"
});

To get a property you can use getStyle() specifying the property you want to get (height, background, color...):

$("myElement").getStyle("height")

The previous code returns the height of the DOM element with ID="myElement", for example "200px". If you want the number (200 and not the string "200px") you have to use the following code:

$("myElement").getStyle("height").toInt()

...in this way the value returned will be a number (200).


4. Unobtrusive Javascript
Now, we can start to see how to write unobtrusive Javascript code using MooTools in order to separate page content from JavaScript code. Your have to use the following code:

<script type="text/javascript">
window.addEvent('domready', function() {
//Some lines of code here...
});
</script>

For example I want to write a simple script which display an alert with "Hello World!" when an user click on a link with ID="myElement". The script is:

<script type="text/javascript">
window.addEvent('domready', function() {
$('myElement').addEvent('click', function() {
alert('Hello World!');
});
});
</script>

...and HTML code is:

<a href="home.html" id="myElement">
Try to click here!
</a>

...instead of an "obtrusive" code with onClick event which calls a function (for example doSomething()) added within the <a> tag:

<a href="home.html" id="myElement" onClick="javascript:doSomething()" >
Try to click here!</a>


Example 1: change background color
Ok, now we can try to write a simple code which change the background color of a layer with ID="myLayer":



HTML code is something like this:

<div id="myLayer">
<a href="#" id="myElement">Change Background</a>
</div>

...how you can see, you don't call a JavaScript function using an event (onClick, onFocus...) within <a> tag. The reference to the DOM element "myLayer" will be insert into the following script which you have to add below the link to the MooTools framework in the <head> tag (step 1):

<script type="text/javascript">
window.addEvent('domready', function() {
$('myElement').addEvent('click', function() {
$('myLayer').setStyle('background', '#DEDEDE');
});
});
</script>


Example 2: change and reset background color
Now we can modify the previous code and make it a little bit more complex. In this example when an user clicks on "Change Background", if the background colors of the layer with ID="myLayer" is not set, then the script sets the background color of the layer to this value "#DEDEDE"; else, the script set the background color to null.




HTML code is the same of the previous example:

<div id="myLayer">
<a href="#" id="myElement">Change Background</a>
</div>

... but I changed something in the script:

<script type="text/javascript">
window.addEvent('domready', function() {
$('myElement').addEvent('click', function() {
var currentBgColor = $('myLayer').getStyle('background');
if(currentBgColor==''){
$('myLayer').setStyle('background', '#DEDEDE');
} else {
$('myLayer').setStyle('background', '#FFFFFF');
}
});
});
</script>


Download source code


How you can see the code is very simple. Now you can start to write more complex functions to manipulate element properties. In the next lesson we we'll see how to interact with Forms using MooTools.

Do you have some suggest? Add a comment!