<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C/DTD XHTML+Voice 1.2 /EN' 'http://www.voicexml.org/specs/multimodal/x+v/12/dtd/xhtml+voice12.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:ev='http://www.w3.org/2001/xml-events'>
<head>
<link rel='canonical' href='http://pabi3.com/blog/progress-bar-cez-javascript-a-css/' />
<link rel='stylesheet' href='http://pabi3.com/modules/items/voice.css' type='text/css' media='all' />
<form xmlns='http://www.w3.org/2001/vxml' id='title'>
<block>
The article Progress Bar cez JavaScript a CSS is written by PaBi3
</block>
</form>
<form xmlns='http://www.w3.org/2001/vxml' id='body'>
<block>


Progress Bar sluzi na vyjadrenie aktualneho stavu urcitej cinnosti. Stretavame sa s nim denne, ci uz pri kopirovani suborov, instalacii aplikacii alebo na internete. Je mozne ho vytvorit za pomoci kratkeho JavaScript a CSS kodu. Vsetko funguje na velmi jednoduchom principe s funkciou setTimeout() a 3 elementmi &lt;div&gt;. Vlastna funkcia stats() ma 3 parametre. Prvy urcuje odkial sa ma zacat zobrazovat stav, druhy urcuje pokial sa ma zobrazovat a posledny nastavi cas, za ktory sa vsetko toto udeje. Dalsou a zaroven poslednou funkciou je process(). Vola sa len cez funkciu setTimeout() a nastavuje sirku elementu &lt;div&gt;. Vysledok si mozete prezriet tu, stiahnut tu a zdrojovy kod najdete po otvoreni celeho clanku.
</block>
</form>
<form xmlns='http://www.w3.org/2001/vxml' id='full'>
<block>
JavaScript
function status(sb_start,sb_end,seconds)
{
	var speed = Math.round(seconds*10);
	var timer = 0;
	for(i = sb_start; i &lt;= sb_end; i++)
	{
		setTimeout(&quot;process(&#039;&quot; + i + &quot;&#039;)&quot;,(timer*speed));
		timer++;
	}
}

function process(status)
{
	var progress = document.getElementById(&#039;status&#039;);
	progress.innerHTML = status + &#039;%&#039;;

	var bar = document.getElementById(&#039;bar&#039;);
	bar.style.width = status + &#039;%&#039;;

	if(status == 100) progress.innerHTML = &#039;Completed&#039;;
}

status(0,100,10);

CSS
* { margin:0; padding:0; }
html, body { font-family:&#039;Tahoma&#039;,&#039;Lucida Grande CE&#039;,lucida,sans-serif; font-size:12px; padding:10px; }

div.statusbar { width:300px; height:25px; border:1px outset silver; background:url(&#039;bar-empty.png&#039;) repeat-x; position:relative; }
div.statusbar div#status { width:300px; height:25px; color:black; font-weight:bold; top:0; left:0; position:absolute; text-align:center; padding:6px; }
div.statusbar div#bar    { width:0%; height:100%; background:url(&#039;bar.png&#039;) repeat-x; text-align:center; }

XHTML
&lt;div class=&#039;statusbar&#039;&gt;
&lt;div id=&#039;bar&#039;&gt;&lt;/div&gt;
&lt;div id=&#039;status&#039;&gt;0%&lt;/div&gt;
&lt;/div&gt;</block>
</form>
<base href='http://pabi3.com/' />
<title>Progress Bar cez JavaScript a CSS</title>
</head>
<body ev:event='load' ev:handler='#title'>
<a href='http://pabi3.com/blog/progress-bar-cez-javascript-a-css/' title='Návrat'>Návrat</a>
<h1 style='padding:0.5em;'>Progress Bar cez JavaScript a CSS</h1>
<ul>
<li ev:event='click' ev:handler='#body'>Speak introduction</li>
<li ev:event='click' ev:handler='#full'>Speak full</li>
</ul>
</body>
</html>

