Wednesday, 10 December 2014

Christmas Candle With jQuery

Christmas Candle With jQuery
Place the mouse pointer over the wick
to put on the fire and click to blow it out.

In my last post I designed a Christmas tree so I felt like making another thing related to Christmas.

This time it is a Christmas candle which you can lit and blow out. The fire and the candle parts are created by div elements. We want to lit the fire when we roll over the candle wick with the mouse. This is done by the mouseover event inside the HTML code.

Now, we want that the candle glimmers in the dark so we use jQuery because with it it's easy to write a code for animated effects. The glimmer effect is created by changing the opacity of the div fire element with the following syntax animate( {opacity:"+= or -= some number between 0 to 1"},{duration:milliseconds});. "+=" creates a fade in effect and "-=" a fade out effect.

By clicking the fire, the candle should stop glimmering. We put the onclick event inside the HTML code and connect it with the function called blow(). jQuery hide() hides the fire element.







HTML & CSS & JavaScript Code


Open The Door With CSS Hover

Open the Door!
Drag the mouse over the door and open it!

The door image is placed inside the door frame created with a div element. The door itself is a png image file.

The CSS transform-origin:right property lets the door shrink from the left to the right side which provides the impression as if the door is opening if you put the cursor on top of the door. To show the effect in all browsers the prefixes -ms- for Internet Explorer and -webkit- for all other browsers have to be put in front of transform-origin.

The duration of the animation is set to 5 seconds with the name "open". The @keyframes property describes details of the animation "open". We want to make a lateral rotation of the door therefore we use the rotateY(deg) property. @keyframes needs the prefix -webkit- as well.

Note:the hover effect is not working on a touch screen.


CSS & HTML Code

Tuesday, 9 December 2014

Blinking Xmas Tree With JavaScript Math.random()

Blinking Xmas Tree With JavaScript Math.random()

Click on the top and let it blink



It's Xmas time! When I was walking in downtown seeing all this beautiful Xmas decorations I was inspired to make my own Xmas tree with JavaScript.

A tree usually has a crown and trunk. The crown of the Xmas tree is made of 3 div elements. 1 green div element has white div elements on the right and left side creating a triangle. The decoration balls are also div elements with a border-radius of 50% defined in CSS.

Now the Xmas tree is ready to blink. So let's look at the JavaScript code. We want that the balls change colours randomly in a certain interval. The Math object with the random () method generates random numbers between 0 and 1; the syntax is Math.random().

Next, we define the colours for each ball with document.getElementById("id of the element").style.backgroundColor=#some color. Now, with Math.random() we generate random numbers and if the number is smaller than 0.5 the balls have colour A and if it is bigger than 0.5 they have colour B.

The method setTimeout evaluates the function for each half second generating random numbers and creating the blinking effect.

Save the CSS file with XMas_tree.css and the JavaScript file with XMas_tree.js otherwise it will not work. Our you can change the file name of css and js in the HTML code.

HTML Code

CSS Code

JavaScript Code

Monday, 8 December 2014

Futuristic Clock With Javascript And jQuery

Futuristic Clock With JavaScript
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.


HTML Code



JavaScript Code



CSS Code

Wednesday, 3 December 2014

Name Tag With Border Style

Name Tag With Border Style
Fat Ladies
Here is another text design looking like a name tag of your clothes. The stitched are created with border-style: dashed. For the top use border-top-style and for the bottom use border-bottom-style. Change the text inside the label and make your own one!

Monday, 1 December 2014

Blinking Neon Sign With jQuery

Blinking Neon Sign With jQuery
Welcome!
You can spice up your website with some JavaScript animation. The example shows a text which fades out and fades in 10 times in a row with the while loop.

jQuery ―which uses the $ sign in front of each element ―makes it easy to write codes for animations. The blinking starts with the value var i=0 and finished after blinking for 10 times which is set as while(i<10). In function() you include the fadeOut() and fadeIn() methods to create the blinking effect. For details, have a look at the code!

CSS, HTML & JavaScript Code

Thursday, 27 November 2014

CSS Flower

CSS Flower
Let flowers bloom with CSS!

The basic structure of the petals are made with 10 div elements. The unique shape of a petal is created by CSS border-top-left-radius and border-bottom-right-radius. The greater the value the rounder the corner gets.

HTML & CSS Code

Wednesday, 26 November 2014

Sweeten Your Text With CSS: Chocolate

Sweeten Your Text With CSS: Chocolate
Chocolate
I love chocolate! So why not making a chocolate like logo? In the example above, I have used 3 different colors: sienna (#D2691E), maroon (#800000) for the highlights and the shadows and chocolate (#D2691E) for the whole bar. It should look like a chocolate bar so I have used border-style:outset in the CSS code. The highlight and shadows of the letters are made with the text-shadow property. After working on this design for 30min I have a graving for chocolate!

CSS & HTML Code

Tuesday, 25 November 2014

CSS Flex: Making A Sunblock

CSS Flex: Making A Sunblock
Here I have designed a window sun block.

The CSS display:flex property makes it super easy to create same sized HTML div elements with different colors.

HTML

The "box" div element contains several div elements describing the color of each element with style="background-color:color".

CSS

The size of the div elements is defined by flex:1. The prefix -webkit- and -ms- is necessary if you want to display it in Safari and Internet Explorer. Don't forget to write display:flex for the "box" div element.

CSS&HTML Code

.

Monday, 24 November 2014

Jeans Style Logo With CSS

Jeans Style Logo With CSS
The border-style allows you to choose different border styles. In the designs above I have used the border-style:dashed to create a label which looks like a stitched one. For details, have a look at the code.


HTML & CSS Code

Friday, 21 November 2014

What Time Is It?

Pink & Black Clock With jQuery

Here, I've created a clock with JavaScript.
First of all, the clock should start working the page has been loaded so we use the onload event. We call the function "clock()".

HTML

To connect the event with the function you have to write onload="clock()" in the body element of the HTML code. The onload event is only valid in the body element. For example, if you put onload in the button element it will do nothing.

JavaScript

We want to get the hours, minutes and seconds so we use the following methods: getHours(), getMinutes() and getSeconds(). The Date() object makes it possible that the actual time is shown. The last line of the code put the hours, minutes and seconds with + together. You have to put something between the variables to make sure everything is displayed; this time I've put colons in between.



HTML Code

CSS Code

JavaScript Code

Thursday, 20 November 2014

Red Neon Sign With CSS

Red Neon Sign With CSS
T-Bone


I wanted to try other colors for a neon style sign and I though red would look nice. So I've used red for text-shadow in CSS. Here is its structure:

text-shadow {y px x px zpx colour;}

The first px value shifts the text horizontally, the second vertically and the last value defines the degree of the blur.


CSS&HTML Code

Wednesday, 19 November 2014

Retro Telly With CSS

tv designed with css
Retro Telly With CSS
This TV includes 6 div elements which display the TV outer box ("telly_frame"), the screen ("screen"), two antennas ("antenna_left", "antenna_right") and the two buttons on the left ("upper_button", "downside_button"). All div elements are put inside the outer box to position the rest of the elements absolute to this element.

The screen, the buttons are relative to the box which is described with the property position:absolute. The metallic effect of the buttons is created with the CSS background:linear-gradient property and don't forget to put the prefixes -o-, -moz- and -webkit- to show it in all browsers.


CSS & HTML CODE

Tuesday, 18 November 2014

Sweeten Your Text With CSS: Mille-Feuille

mille-feuille style letters designed with css
Mille-Feuille Style Text With CSS
Mille-Feuille
This text design has been inspired by the pastry mille-feuille. I've used 4 different colours in the CSS text-shadow property to express the different layers of the cake. If you create several layers in text-shadow separate them with "," and just the last line with ";" to make it work.


HTML&CSS

Monday, 17 November 2014

Fading Buttons With CSS Flex

dots created with the css property flex
Fading Buttons With CSS Flex
Blue
Yellow
Green
Red
Orange
Pink
Here we have same sized buttons. CSS flex property makes it easy to create same sized objects. To make them more exciting I have added the transition property to them as well. The flex property can also be wrapped by using flex-wrap:wrap. To show it in Chrome, Safari and Opera don't forget to put the prefix -webkit- in front of flex-wrap.The border-radius has been set to 50% for the circles.
Note that hover will not work on a tablet.


HTML&CSS