gpt4 book ai didi

javascript - 使用 jquery 进行文本旋转

转载 作者:行者123 更新时间:2023-11-28 16:00:29 25 4
gpt4 key购买 nike

您好,我目前正在使用 jquery 编写文本旋转代码,

var rotation = 0;

jQuery.fn.rotate = function(degrees) {
$(this).css({'transform' : 'rotate('+ degrees +'deg)'});
};

$('.resizeButton').click(function() {
rotation += 5;
$('.new-div').rotate(rotation);
});

请看这个。 https://jsfiddle.net/felixtm/2mpjkxad/3/

但是这里的文本旋转发生在鼠标点击那个调整大小按钮时。而不是鼠标单击用户能够像往常一样旋转文本旋转事件。 IE。使用单击按钮按他的意愿旋转它。这里他需要点击很多次才能进行一次大的旋转。怎么办?

UPDATE : I see this question that is exactly what i wanted .But i don't know how to implement it . jQuery: Detecting pressed mouse button during mousemove event

最佳答案

尝试这样的事情:

var rotation = 0;

jQuery.fn.rotate = function(degrees) {
$(this).css({'transform' : 'rotate('+ degrees +'deg)'});
};

$('.resizeButton').on("mousedown", function(e) {
var startX = e.pageX;
$(document).mousemove(function(e){
rotation = startX - e.pageX;
$('.new-div').rotate(rotation);
});
});
$('.resizeButton').on("mouseup", function(){
$(document).unbind( "mousemove" );
});

https://jsfiddle.net/p9wtmfhp/

关于javascript - 使用 jquery 进行文本旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40238996/

25 4 0
文章推荐: ios - CollectionView 单元格在选中时移动
文章推荐: html - 将 标签置于
  • 的中心