我想让用户像在 Photoshop 中一样旋转图像,我创建了一个小提琴。旋转度数感觉有问题,挣扎了很久,请求帮助。
Js Fiddle 链接 - http://jsfiddle.net/madhuri2987/fZegT/8/
全屏 - http://jsfiddle.net/madhuri2987/fZegT/8/embedded/result/
HTML
<div id="mainTarget">
<img src="http://myreaxns.com/wp-content/uploads/2013/03/priyanka-chopra-image.jpg" width="300" class="mainTarget" />
<div id="target"> </div>
</div>
JS
$(window).load(function(){
var dragging = false
$(function() {
var target = $('#target');
var mainTarget = $('#mainTarget');
target.mousedown(function() {
dragging = true
})
$(document).mouseup(function() {
dragging = false
})
$(document).mousemove(function(e) {
if (dragging) {
var mouse_x = e.pageX;
var mouse_y = e.pageY;
var radians = Math.atan2(mouse_x - 10, mouse_y - 10);
var degree = (radians * (180 / Math.PI) * -1) + 90;
mainTarget.css('-moz-transform', 'rotate(' + degree + 'deg)');
mainTarget.css('-moz-transform-origin', '50% 50%');
mainTarget.css('-webkit-transform', 'rotate(' + degree + 'deg)');
mainTarget.css('-webkit-transform-origin', '50% 50%');
mainTarget.css('-o-transform', 'rotate(' + degree + 'deg)');
mainTarget.css('-o-transform-origin', '50% 50%');
mainTarget.css('-ms-transform', 'rotate(' + degree + 'deg)');
mainTarget.css('-ms-transform-origin', '50% 50%');
}
})
})
});