問題我在IE中正在旋轉一個圖像(時鐘指針)。下面的腳本在一定程度上工作(實際上有動畫正在進行),但它完全離軸旋轉。IE8中的Javascript/css
我決不是一個使用JavaScript/Jquery的智力遊戲,當談到如何在IE8中正確地做到這一點時,我有點失落。
代碼如下:
(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;
};
你能再做一些特別的嗎? FIC?另外,試試拉斐爾。它在IE瀏覽器中工作,看起來很棒:http://raphaeljs.com/polar-clock.html – Blender 2012-03-28 16:06:29
恐怕「不吉利」沒有描述代碼的確切問題... – Pointy 2012-03-28 16:20:21
@Pointy更新了這個問題。雙手完全離開軸線旋轉。 – Plastika 2012-03-28 16:34:22