
How about a futuristic looking clock for a web widget?
For fade out and fade in animation we use JavaScript and jQuery.
The clock is designed with CSS. Each panel has its own div element. The opacity of the green squares is set to 0 meaning that they are basically invisible. The panel showing the actual time is another div element. Never put the div elements associated with the green squares inside the panel element! Because if you set JavaScript both to a parent and child elements the script will not fire. Both codes have to be in different elements.
Now, we have designed the clock and the squares so we are ready to make them work together. First of all, the time should be shown in the center panel so we create a Date() object with JavaScript. Get the hours with getHours(), the minutes with getMinutes() and the seconds with getSeconds() and concatenate the methods with the date object.
Next, for each second passed by a square should fade out and the next should fade in. This is can be done with the animate() method of jQuery which is a part of JavaScrip library and is very useful.
The elements are choosen through their ids with ("$id of the element") and the animation is created with animate({}). The details of the animation are described in the curly brackets. We want that the squares will fade in gradually so we use opacity:"+=1". After 1 s has passed we want to make sure that the same square will fade out so we write opacity:"-=1". Note that if you use hide() once the square has vanished the same square will never appear again.
To link the div squares with the seconds we use the if/else conditional. The if/else conditional is inside the clock() function so we can use the variables declared previously.
For fade out and fade in animation we use JavaScript and jQuery.
The clock is designed with CSS. Each panel has its own div element. The opacity of the green squares is set to 0 meaning that they are basically invisible. The panel showing the actual time is another div element. Never put the div elements associated with the green squares inside the panel element! Because if you set JavaScript both to a parent and child elements the script will not fire. Both codes have to be in different elements.
Now, we have designed the clock and the squares so we are ready to make them work together. First of all, the time should be shown in the center panel so we create a Date() object with JavaScript. Get the hours with getHours(), the minutes with getMinutes() and the seconds with getSeconds() and concatenate the methods with the date object.
Next, for each second passed by a square should fade out and the next should fade in. This is can be done with the animate() method of jQuery which is a part of JavaScrip library and is very useful.
The elements are choosen through their ids with ("$id of the element") and the animation is created with animate({}). The details of the animation are described in the curly brackets. We want that the squares will fade in gradually so we use opacity:"+=1". After 1 s has passed we want to make sure that the same square will fade out so we write opacity:"-=1". Note that if you use hide() once the square has vanished the same square will never appear again.
To link the div squares with the seconds we use the if/else conditional. The if/else conditional is inside the clock() function so we can use the variables declared previously.