Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This should work across all browsers, including IE8: <a href="http://jsfiddle.net/SrSus/26/show/" rel="nofollow">http://jsfiddle.net/SrSus/26/show/</a></p> <p><strong>HTML</strong></p> <pre><code>&lt;ul id="analog-clock" class="analog"&gt; &lt;li class="hour"&gt;&lt;/li&gt; &lt;li class="min"&gt;&lt;/li&gt; &lt;li class="sec"&gt;&lt;/li&gt; &lt;li class="meridiem"&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p><strong>Javascript</strong></p> <pre><code>(function ($) { $.fn.clock = function (options) { var self = this, el, msie8 = (/(msie) ([\w.]+)/i).test(navigator.userAgent), defaults = { offset: "+0" }, opts = $.extend(defaults, options), calcTime = function (offset) { var d = new Date(), utc = d.getTime() + (d.getTimezoneOffset() * 60000), nd = new Date(utc + (3600000 * offset)); return nd; }, rotate = function (o, degree) { var rotate = "rotate(" + degree + "deg)", rad, cos, sin, w, h; if (o.cur === degree) { return; } o.cur = degree; if (msie8) { rad = (degree * Math.PI) / 180; cos = Math.cos(rad); sin = Math.sin(rad); o.el.css({ 'filter': 'progid:DXImageTransform.Microsoft.Matrix(sizingMethod="auto expand", M11 = ' + cos + ', M12 = ' + (-sin) + ', M21 = ' + sin + ', M22 = ' + cos + ')' }); w = o.el.width(); // obtain element sizes again h = o.el.height(); o.el.css({ "marginLeft": -Math.round((w - o.w) / 2), "marginTop": -Math.round((h - o.h) / 2) }); } else { o.el.css({ "-moz-transform": rotate, "-webkit-transform": rotate, "-ms-transform": rotate, "-sand-transform": rotate }); } }; // store elements and sizes el = $(self).children(".sec"); opts.sec = { el: el, w: el.width(), h: el.height(), cur: null }; el = $(self).children(".hour"); opts.hour = { el: el, w: el.width(), h: el.height(), cur: null }; el = $(self).children(".min"); opts.min = { el: el, w: el.width(), h: el.height(), cur: null }; setInterval(function () { var time = calcTime(opts.offset), hours = time.getHours(), mins = time.getMinutes(), seconds = time.getSeconds(), degree; // hours degree = hours * 30 + (mins / 2); rotate(opts.hour, degree); // minutes degree = mins * 6; rotate(opts.min, degree); // seconds degree = seconds * 6; rotate(opts.sec, degree); }, 1000); }; })($); $("#analog-clock").clock(); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload