Yi *_*ang 12
使用jQuery UI的原始拖动事件:
$('selector').draggable({
drag: function(event, ui){
var rotateCSS = 'rotate(' + ui.position.left + 'deg)';
$(this).css({
'-moz-transform': rotateCSS,
'-webkit-transform': rotateCSS
});
}
});
Run Code Online (Sandbox Code Playgroud)
问题是你的问题稍微不清楚是如何处理由此产生的两种行为(当你拖动对象同时旋转和移动时)的冲突.这个只是让鼠标的左右移动决定旋转多少,而默认的拖动行为(移动)仍然存在.
我想这有点hackish但它会起作用:
// Your original element
var ele = $('#selector');
// Create handle dynamically
$('<div></div>').appendTo(ele).attr('id','handle').css({
'position': 'absolute',
'bottom': 5,
'right': 5,
'height': 10,
'width': 10,
'background-color': 'orange'
});
ele.css('position', 'relative');
$('#handle').draggable({
handle: '#handle',
opacity: 0.01,
helper: 'clone',
drag: function(event, ui){
var rotateCSS = 'rotate(' + ui.position.left + 'deg)';
$(this).parent().css({
'-moz-transform': rotateCSS,
'-webkit-transform': rotateCSS
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18696 次 |
| 最近记录: |