2D图像旋转javascript在所有浏览器中工作.需要帮助修复我的代码
2D image rotation javascript to work in all browsers. Help needed to fix my code
我试图有一个简单的图像旋转来回鼠标点击。我一直在尝试使用jQuery。我写的代码在Safari, Firefox和Chrome中都可以正常工作。问题出在ie9、ie11和ie10上,我不需要测试它们。我做了一个测试页面,任何人都可以看到我完成了什么,并测试自己在IE中发生了什么。这是我的测试页面的链接我很感激如果有人指出我使用的代码添加或删除什么,使其在IE 10和11中工作的方式与上面提到的其他浏览器中的工作方式相同。
非常感谢!
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>.rotate() - Simple rotation on mouse click of the image</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><style type="text/css"></style>
<style type="text/css"> body {
padding:0px;
background: transparent;
}
img {
margin-bottom:0px;
}</style>
<script type="text/javascript">//<![CDATA[
// .rotate() cross
$(function() {
$('#btn3').toggle(function() {
$(this).rotate({ endDeg:90, persist:true });
}, function() {
$(this).rotate({ endDeg:45 });
});
})
$.fn.rotate=function(options) {
var $this=$(this), prefixes, opts, wait4css=0;
prefixes=['-Webkit-', '-Moz-', '-O-', '-ms-', ''];
opts=$.extend({
startDeg: false,
endDeg: 360,
duration: .25,
count: 1,
easing: 'linear',
animate: {},
forceJS: false
}, options);
function supports(prop) {
var can=false, style=document.createElement('div').style;
$.each(prefixes, function(i, prefix) {
if (style[prefix.replace(/'-/g, '')+prop]==='') {
can=true;
}
});
return can;
}
function prefixed(prop, value) {
var css={};
if (!supports.transform) {
return css;
}
$.each(prefixes, function(i, prefix) {
css[prefix.toLowerCase()+prop]=value || '';
});
return css;
}
function generateFilter(deg) {
var rot, cos, sin, matrix;
if (supports.transform) {
return '';
}
rot=deg>=0 ? Math.PI*deg/180 : Math.PI*(360+deg)/180;
cos=Math.cos(rot);
sin=Math.sin(rot);
matrix='M11='+cos+',M12='+(-sin)+',M21='+sin+',M22='+cos+',SizingMethod="auto expand"';
return 'progid:DXImageTransform.Microsoft.Matrix('+matrix+')';
}
supports.transform=supports('Transform');
supports.transition=supports('Transition');
opts.endDeg*=opts.count;
opts.duration*=opts.count;
if (supports.transition && !opts.forceJS) { // CSS-Transition
if ((/Firefox/).test(navigator.userAgent)) {
wait4css=(!options||!options.animate)&&(opts.startDeg===false||opts.startDeg>=0)?0:25;
}
$this.queue(function(next) {
if (opts.startDeg!==false) {
$this.css(prefixed('transform', 'rotate('+opts.startDeg+'deg)'));
}
setTimeout(function() {
$this
.css(prefixed('transition', 'all '+opts.duration+'s '+opts.easing))
.css(prefixed('transform', 'rotate('+opts.endDeg+'deg)'))
.css(opts.animate);
}, wait4css);
setTimeout(function() {
$this.css(prefixed('transition'));
if (!opts.persist) {
$this.css(prefixed('transform'));
}
next();
}, (opts.duration*1000)-wait4css);
});
} else { // JavaScript-Animation + filter
if (opts.startDeg===false) {
opts.startDeg=$this.data('rotated') || 0;
}
opts.animate.perc=100;
$this.animate(opts.animate, {
duration: opts.duration*1000,
easing: $.easing[opts.easing] ? opts.easing : '',
step: function(perc, fx) {
var deg;
if (fx.prop==='perc') {
deg=opts.startDeg+(opts.endDeg-opts.startDeg)*perc/100;
$this
.css(prefixed('transform', 'rotate('+deg+'deg)'))
.css('filter', generateFilter(deg));
}
},
complete: function() {
if (opts.persist) {
while (opts.endDeg>=360) {
opts.endDeg-=360;
}
} else {
opts.endDeg=0;
$this.css(prefixed('transform'));
}
$this.css('perc', 0).data('rotated', opts.endDeg);
}
});
}
return $this;
};
//]]></script>
</head>
<body>
<img src="http://f.cl.ly/items/2B0t0j1c2P0m2B080D2H/RedCross-.gif" id="btn3">
</body></html>
参考这个JSFiddle
JQuery$('a').click(function(){
var a = $('img').getRotateAngle();
var d = Math.abs($('#degree').val());
if($(this).attr('id') == 'counter'){
//d = -Math.abs(+a - +d);
d = a - d;
}
else{d = +a + +d;}
$('img').rotate({animateTo:d});
});
/* image preview */
$('#file').change(function(){
var oFReader = new FileReader();
oFReader.readAsDataURL(this.files[0]);
console.log(this.files[0]);
oFReader.onload = function (oFREvent) {
$('#preview').html('<img src="'+oFREvent.target.result+'">');
};
});
相关文章:
- 需要帮助编写在不使用toString的情况下将十进制转换为二进制的代码
- 需要帮助调整 Fiddle 代码以使用 Javascript 和 CSS 折叠/展开 Div
- Javascript 我正在尝试用 noloop() 暂停球;但是在键向上我想继续球反弹,你能看看我的代码并帮助我吗?
- 需要帮助将此JavaScript代码应用于我现有的代码
- 需要通过Javascript代码应用样式的帮助
- 关于jQuery代码的Internet Explorer错误帮助
- node.js nodeschool learnyounode需要帮助理解解决方案的代码
- Javascript:Coderbyte挑战4:字母变化:帮助分析代码:这是如何大写元音的,以及何时执行else语句
- Caesar密码在html中使用javascript(带有ASCII代码)需要帮助
- 使用 HTML + Javascript 的多项选择测验:回复:使用数组对象和属性更新分数(帮助分析代码)
- 需要帮助将一些JavaScript代码添加到我的wordpress主题中
- PARSE.COM - 使用 AnyMeme 云代码教程需要帮助
- 任何人都可以帮助我编写代码,以便在 extjs 4.2 的组合框中制作带有复选框的面板
- ExtJS 4 代码在 Aptana 3 中提供帮助
- 弹跳图像帮助代码不会在 JSFIDDLE 之外摇摆不定
- 请帮助将简短的jquery代码转换为javascript
- 需要帮助来清理我的代码
- 有人请帮助解释这个javascript代码,即发生了什么以及代码在做什么
- JAVASCRIPT帮助-代码不起作用
- 需要帮助-代码更改下拉选项表单-更改提交到URL链接