Issue I am having is rotating an image (clock hands to be precise) in IE. The script below works to an extent (there is actually animation going on) but it's rotating completely off axis.
I am by no means a wiz with Javascript/Jquery and am a bit lost when it comes to working out how to do this properly in IE8.
Code below:
(function(jQuery)
{
jQuery.fn.clock = function(options)
{
var defaults = {
offset: '+0',
type: 'analog'
};
var _this = this;
var opts = jQuery.extend(defaults, options);
setInterval( function() {
var seconds = jQuery.calcTime(opts.offset).getSeconds();
if(opts.type=='analog')
{
var sdegree = seconds * 6;
var srotate = "rotate(" + sdegree + "deg)";
var rad = Math.PI/180 * sdegree,
cos = Math.cos(rad),
sin = Math.sin(rad);
jQuery(_this).find(".sec").css({"-moz-transform" : srotate, "-webkit-transform" : srotate, "-ms-transform" : srotate,
'filter': "progid:DXImageTransform.Microsoft.Matrix(M11="+cos+", M12="+(-sin)+", M21="+sin+", M22="+cos+", SizingMethod='auto expand')"});
}
else
{
jQuery(_this).find(".sec").html(seconds);
}
}, 1000 );
setInterval( function() {
var hours = jQuery.calcTime(opts.offset).getHours();
var mins = jQuery.calcTime(opts.offset).getMinutes();
if(opts.type=='analog')
{
var hdegree = hours * 30 + (mins / 2);
var hrotate = "rotate(" + hdegree + "deg)";
var rad = Math.PI/180 * hdegree,
cos = Math.cos(rad),
sin = Math.sin(rad);
jQuery(_this).find(".hour").css({"-moz-transform" : hrotate, "-webkit-transform" : hrotate, "-ms-transform" : hrotate,
'filter': "progid:DXImageTransform.Microsoft.Matrix(M11="+cos+", M12="+(-sin)+", M21="+sin+", M22="+cos+", SizingMethod='auto expand')"});
}
else
{
jQuery(_this).find(".hour").html(hours+':');
}
var meridiem = hours<12?'AM':'PM';
jQuery(_this).find('.meridiem').html(meridiem);
}, 1000 );
setInterval( function() {
var mins = jQuery.calcTime(opts.offset).getMinutes();
if(opts.type=='analog')
{
var mdegree = mins * 6;
var mrotate = "rotate(" + mdegree + "deg)";
var rad = Math.PI/180 * mdegree,
cos = Math.cos(rad),
sin = Math.sin(rad);
jQuery(_this).find(".min").css({"-moz-transform" : mrotate, "-webkit-transform" : mrotate, "-ms-transform" : mrotate,
'filter': "progid:DXImageTransform.Microsoft.Matrix(M11="+cos+", M12="+(-sin)+", M21="+sin+", M22="+cos+", SizingMethod='auto expand')"});
}
else
{
jQuery(_this).find(".min").html(mins+':');
}
}, 1000 );
}
})(jQuery);
jQuery.calcTime = function(offset) {
d = new Date();
utc = d.getTime() + (d.getTimezoneOffset() * 60000);
nd = new Date(utc + (3600000*offset));
return nd;
};
This should work across all browsers, including IE8: http://jsfiddle.net/SrSus/26/show/
HTML
Javascript
Check this example: This is working on IE...
This is a function of a plugin that i made for drawing lines in an html element... It uses rotations for oblique lines. if you want to check the entire plugin go to: https://github.com/tbem/jquery.line