我想讓用戶像我們在photoshop中一樣旋轉圖像,我創建了一個小提琴。 旋轉角度感覺不對,長時間掙扎,請求幫助。允許用戶用css和jquery旋轉圖像
的js小提琴鏈接 - 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%');
}
})
})
});
謝謝你..真正有用.. – itsMe