
Proč je JavaScript v IE nefunkční a v ostatních Browserech jde ?
HTML
<!DOCTYPE html>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<head>
<title>Analog Clock</title>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body onload="startClock()">
<div id="hodiny">
<div class="clock">
<h2>Lorem ipsum <br>dolor sit amet</h2>
<div class="analog-clock">
<svg width="140" height="125">
<circle id="clock-face" cx="70" cy="70" r="50" />
<line id="h-hand" x1="70" y1="70" x2="70" y2="45" />
<line id="m-hand" x1="70" y1="70" x2="70" y2="33" />
<line id="s-hand" x1="70" y1="70" x2="70" y2="31" />
<line id="s-tail" x1="70" y1="70" x2="70" y2="56" />
</svg><h3>20%</h3><h4>Lorem ipsum dolor sit amet</h4>
<hr align="center" color="#5d5d5d" id="cara">
<h5>Lorem! ipsum dolor sit</h5>
<img id="obrazek" src="hodiny.png"height="129" width="127">
</div>
</div>
</div>
</body>
</html>
Script
function clock(){
//calculate angle
var d, h, m, s;
d = new Date;
h = 30 * ((d.getHours() % 24) + d.getMinutes() / 60);
m = 6 * d.getMinutes();
s = 6 * d.getSeconds();
//move hands
setAttr('h-hand', h);
setAttr('m-hand', m);
setAttr('s-hand', s);
setAttr('s-tail', s+180);
//display time
h = d.getHours();
m = d.getMinutes();
s = d.getSeconds();
//call every second
setTimeout(clock, 1000);
};
function setAttr(id,val){
var v = 'rotate(' + val + ', 70, 70)';
document.getElementById(id).setAttribute('transfor m', v);
};
function setText(id,val){
if(val < 10){
val = '0' + val;
}
document.getElementById(id).innerHTML = val;
};
window.onload=clock;