• Feed RSS
Showing posts with label HTML5. Show all posts
Showing posts with label HTML5. Show all posts

Brilliant and Useful HTML5 Tutorials You Must See

read more

How to create a Progress bar with HTML5 Canvas

"
There is a great amount of articles about Canvas on the internet, but I would like to show the example of how you can use Canvas on practice, namely the creation of animated progress bar.
Those who are impatient can find the result of the experiment here, as well as a screenshot of the final result:
The progress bar has turned out pretty simple, but at the same time, in the style of Web 2.0 – round (of course!), with elements of depth and volume: that is, shadows and gradients.

Substrate

Let’s start with a substrate, which will be filled with progress. We are going to round the angles of the rectangle with the help of arc () function, so in this case the rectangle will always be rounded at the angles in a way of semicircles. To create an arbitrary rounding (as when using a border-radius) it is sufficient to use two Bezier curves (Bezier and quadratic curves) and direct interval between them (degenerating to a point in a semicircle, as in our case). Thus, the function of creation of the substrate’s filled outline will look in the following way:
function roundRect(ctx, x, y, width, height, radius) {
   ctx.beginPath();
   ctx.moveTo(x + radius, y);
   ctx.lineTo(x + width - radius, y);
   ctx.arc(x+width-radius, y+radius, radius, -Math.PI/2, Math.PI/2, false);
   ctx.lineTo(x + radius, y + height);
   ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
   ctx.closePath();
   ctx.fill();
}
Then we add shadows and volume to the substrate. Create volume using a linear gradient with three stops, the shadows – with the standard properties of the context:
function progressLayerRect(ctx, x, y, width, height, radius) {
   ctx.save();
   // Define the shadows
   ctx.shadowOffsetX = 2;
   ctx.shadowOffsetY = 2;
   ctx.shadowBlur = 5;
   ctx.shadowColor = '#666';

    // first grey layer
   ctx.fillStyle = 'rgba(189,189,189,1)';
   roundRect(ctx, x, y, width, height, radius);

   // second layer with gradient
   // remove the shadow
   ctx.shadowColor = 'rgba(0,0,0,0)';
   var lingrad = ctx.createLinearGradient(0,y+height,0,0);
   lingrad.addColorStop(0, 'rgba(255,255,255, 0.1)');
   lingrad.addColorStop(0.4, 'rgba(255,255,255, 0.7)');
   lingrad.addColorStop(1, 'rgba(255,255,255,0.4)');
   ctx.fillStyle = lingrad;
   roundRect(ctx, x, y, width, height, radius);

   ctx.restore();
}
Two layers are being used here – the lower solid gray and the top white with gradients of transparency. In my opinion it provides more precise boundaries of the substrate and looks more realistic, in any case you can always experiment with all the color settings. If everything was done correctly, you will get something like this:

Progress bar

Now let’s move to the creation of progress that will fill the substrate. Progress – it’s the same rectangle with rounded angles, it only has a different color. But it has a special feature that differs it from the substrate and which should be taken into account in drawing – when the width of the progress is less than the radius of rounding and when the width is greater than the length of the substrate minus radius. In this case it is necessary to determine the angles of rounding’s drawing and the position of chord of circle, all the calculations can be made with the help of geometry course, see the picture below:
Plus we add the shadow on the right angle of the progress to attach the volume effect. At the end we get the following drawing code of the progress:
function progressBarRect(ctx, x, y, width, height, radius, max) {
   // deplacement for chord drawing
   var offset = 0;
   ctx.beginPath();
   if (width<radius) {
       offset = radius - Math.sqrt(Math.pow(radius,2)-Math.pow((radius-width),2));
       // Left angle
       var left_angle = Math.acos((radius - width) / radius);
       ctx.moveTo(x + width, y+offset);
       ctx.lineTo(x + width, y+height-offset);
       ctx.arc(x + radius, y + radius, radius, Math.PI - left_angle, Math.PI + left_angle, false);
   }
   else if (width+radius>max) {
       offset = radius - Math.sqrt(Math.pow(radius,2)-Math.pow((radius - (max-width)),2));
       // Right angle
       var right_angle = Math.acos((radius - (max-width)) / radius);
       ctx.moveTo(x + radius, y);
       ctx.lineTo(x + width, y);
       ctx.arc(x+max-radius, y + radius, radius, -Math.PI/2, -right_angle, false);
       ctx.lineTo(x + width, y+height-offset);
       ctx.arc(x+max-radius, y + radius, radius, right_angle, Math.PI/2, false);
       ctx.lineTo(x + radius, y + height);
       ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
   }
   else {
       ctx.moveTo(x + radius, y);
       ctx.lineTo(x + width, y);
       ctx.lineTo(x + width, y + height);
       ctx.lineTo(x + radius, y + height);
       ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
   }
   ctx.closePath();
   ctx.fill();

   // shadow on the right
   if (width<max-1) {
       ctx.save();
       ctx.shadowOffsetX = 1;
       ctx.shadowBlur = 1;
       ctx.shadowColor = '#666';
       if (width+radius>max)
           offset = offset+1;
       ctx.fillRect(x+width,y+offset,1,total_height-offset*2);
       ctx.restore();
   }
}
Here, unlike the previous function, we don’t save and renew the context as in case with the substrate, because we are going to define context’s global attributes for the progress.

Text of the progress

Now we add the text that will display the state of progress in per cent. If the length of the text is less than the length of the progress, text will be placed directly at the right angle of the progress, otherwise it will be on the left angle of the progress. To measure the text length we use measureText() function:
function progressText(ctx, x, y, width, height, radius, max) {
   ctx.save();
   ctx.fillStyle = 'white';
   var text = Math.floor(width/max*100)+"%";
   var text_width = ctx.measureText(text).width;
   var text_x = x+width-text_width-radius/2;
   if (width<=radius+text_width) {
       text_x = x+radius/2;
   }
   ctx.fillText(text, text_x, y+22);
   ctx.restore();
}

Full-fledged progress indicator

Now we need to unite all the parts together and define the animation that will fill the progress from 0 to 100%. To create the animation we use sеtInterval() and clearInterval() functions:
// Define the size and position of indicator
var i = 0;
var res = 0;
var context = null;
var total_width = 300;
var total_height = 34;
var initial_x = 20;
var initial_y = 20;
var radius = total_height/2;

window.onload = function() {
   // Get the canvas element
   var elem = document.getElementById('myCanvas');
   // Check the canvas support with the help of browser
   if (!elem || !elem.getContext) {
       return;
   }

   context = elem.getContext('2d');
   if (!context) {
       return;
   }

   // Text’s font of the progress
   context.font = "16px Verdana";

   // Gradient of the progress
   var progress_lingrad = context.createLinearGradient(0,initial_y+total_height,0,0);
   progress_lingrad.addColorStop(0, '#4DA4F3');
   progress_lingrad.addColorStop(0.4, '#ADD9FF');
   progress_lingrad.addColorStop(1, '#9ED1FF');
   context.fillStyle = progress_lingrad;

   // Create the animation
   res = setInterval(draw, 50);
}

function draw() {
   // augment the length on 1 for every iteration
   i+=1;

   // Clear the layer
   context.clearRect(initial_x-5,initial_y-5,total_width+15,total_height+15);
   progressLayerRect(context, initial_x, initial_y, total_width, total_height, radius);
   progressBarRect(context, initial_x, initial_y, i, total_height, radius, total_width);
   progressText(context, initial_x, initial_y, i, total_height, radius, total_width );
   // stop the animation when it reaches 100%
   if (i>=total_width) {
       clearInterval(res);
   }
}
That’s all, now all we need is to put javascript code in script tag, and in body document we should add:
<canvas id="myCanvas" width="500" height="150">Your browser does not have support for canvas.</canvas>
The link for the final result: http://pastehtml.com/view/1d7z824.html

Inset Shadow

The thing is that there is no such tools for creation of the inset shadow in canvas as easy as in CSS, and the essence of the method described above is in using the «Opposite winding» technique that also can be used in canvas. And finally, I prepared another style of the substrate that can be created with the help of inset shadow, in this case the substrate will be sunken inside. The original idea was taken here: http://weblog.bocoup.com/can-i-draw-an-inset-shadow-with-the-html5-canvas-api
To reach the desirable effect first you need to draw an inset shadow, you will first need to punch the shape of your hole in a clockwise direction, onto a large square being drawn in an anti-clockwise direction. Once you have done this, it’s simply a matter of adding your shadow parameters to the Canvas context. To get the inset shadow effect we need to create a new function roundInsetRect() and to modify progressLayerRect() function in the following way:
function roundInsetRect(ctx, x, y, width, height, radius) {
   ctx.beginPath();

   // draw the outward rectangle in an anti-clockwise direction
   ctx.moveTo(1000, 1000);
   ctx.lineTo(1000, -1000);
   ctx.lineTo(-1000, -1000);
   ctx.lineTo(-1000, 1000);
   ctx.lineTo(1000, 1000);

   ctx.moveTo(x + radius, y);
   ctx.lineTo(x + width - radius, y);
   ctx.arc(x+width-radius, y+radius, radius, -Math.PI/2, Math.PI/2, false);
   ctx.lineTo(x + radius, y + height);
   ctx.arc(x+radius, y+radius, radius, Math.PI/2, 3*Math.PI/2, false);
   ctx.closePath();
   ctx.fill();
}
function progressLayerRect(ctx, x, y, width, height, radius) {
   ctx.save();
   // define the shadows
   ctx.shadowOffsetX = 2;
   ctx.shadowOffsetY = 2;
   ctx.shadowBlur = 5;
   ctx.shadowColor = '#666';

    // first gray layer
   ctx.fillStyle = 'rgba(189,189,189,1)';
   roundRect(ctx, x, y, width, height, radius);

   ctx.fillStyle = 'white';
   roundInsetRect(ctx, x, y, width, height, radius);

   ctx.restore();
}
Here you can see the way it will look: http://pastehtml.com/view/1d80e6t.html
"
read more

30 Helpful Tutorials How to Creating HTML5/CSS3 Forms

"
Web forms are very helpful in interaction between a web site and the users. It should be simple, functional, and beautiful. So, whether you are going to add contact us form or sign up form, there is no doubt, that with CSS3 you’ll create something creative and special with its great specifications such as box-shadow, text-shadow, transition, etc.. You should definitely check out the tutorials on creating HTML5/CSS3 Forms we’ve complied for you.

Design a Prettier Web Form with CSS 3

Design a Prettier Web Form with CSS 3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Glowform by kaylarose

Glowform by kaylarose in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Clean and Stylish CSS3 Form

Clean and Stylish CSS3 Form in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

How to Create A Multi-Step Signup Form With CSS3 and jQuery

How to Create A Multi-Step Signup Form With CSS3 and jQuery in Creating HTML5/CSS3 Forms: 30 Helpful TutorialsDownload

Carbon Fiber Signup Form With PHP, jQuery and CSS3

Carbon Fiber Signup Form With PHP, jQuery and CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

How to Build Cross-Browser HTML5 Forms

How to Build Cross-Browser HTML5 Forms in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Create a Stylish Contact Form with HTML5 & CSS3

Create a Stylish Contact Form with HTML5 & CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

CSS3 form without images and JavaScript

CSS3 form without images and JavaScript in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Beautiful CSS3 Search Form

Beautiful CSS3 Search Form in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Create a Slick CSS3 Login Form NO IMAGES ALLOWED

Create a Slick CSS3 Login Form NO IMAGES ALLOWED in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

FormBox – A jQuery & CSS3 Drop-Down Menu With Integrated Forms

FormBox – A jQuery & CSS3 Drop-Down Menu With Integrated Forms in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Fun with HTML5 Forms

Fun with HTML5 Forms in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Styling a Simple Form using CSS3

Styling a Simple Form using CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Designing Modern Web Forms with HTML 5 and CSS3

Designing Modern Web Forms with HTML 5 and CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Create A Clean and Stylish CSS3 Contact Form

Create A Clean and Stylish CSS3 Contact Form in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Creating a Neon Blink Effect for your Forms using CSS3 and jQuery

Creating a Neon Blink Effect for your Forms using CSS3 and jQuery in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Beautiful Form With CSS3

 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Customizing web forms with CSS3 and WebKit

Customizing web forms with CSS3 and WebKit in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Designing Contact form in CSS3 and HTML5

Designing Contact form in CSS3 and HTML5 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Create a Clean and Stylish Login Form With HTML5 and CSS3

Create a Clean and Stylish Login Form With HTML5 and CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

How to Create a Contact Form using HTML5, CSS3 and PHP

How to Create a Contact Form using HTML5, CSS3 and PHP in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

Free slick css form

Free slick css form in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

HTML5 and CSS3 fancy form

 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

HTML5 & CSS3 envelope contact form

HTML5 & CSS3 envelope contact form in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Create an appealing form using some simple CSS3

Create an appealing form using some simple CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials

Styling HTML5 Form Validation Errors

 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo

Designing Form in HTML5 and CSS3

Designing Form in HTML5 and CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials Demo Download

HTML5 Form with CSS

HTML5 Form with CSS in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials

Designing Search Boxes with HTML5 and CSS3

Designing Search Boxes with HTML5 and CSS3 in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials

HTML5′s New “form” Attribute

HTML5′s New “form” Attribute in Creating HTML5/CSS3 Forms: 30 Helpful TutorialsDemo

Bonus

HTML5 formbuilder

HTML5 formbuilder in Creating HTML5/CSS3 Forms: 30 Helpful Tutorials

"

read more