gpt4 book ai didi

javascript - 使用 jquery 和 css 单击按钮后旋转 div 文本

转载 作者:行者123 更新时间:2023-11-28 16:17:06 24 4
gpt4 key购买 nike

我想在使用 jquery 和 css 单击按钮后旋转 div 文本

如果用户点击 Rotate Left 按钮然后文本在左侧旋转
或者
用户点击 Rotate Right 按钮然后文本在右侧旋转

示例:

<div id="RotateDiv">Happy Birthday</div>

<button id="btnRotateLeft" type="button">Rotate Left</button>
<button id="btnRotateRight" type="button">Rotate Right</button>

最佳答案

试试这个:

演示:http://jsfiddle.net/ehec1gun/

var rotation = 0;

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

$('#btnRotateRight').click(function() {
rotation += 5;
$('.rotate').rotate(rotation);
});

$('#btnRotateLeft').click(function() {
rotation -= 5;
$('.rotate').rotate(rotation);
});

关于javascript - 使用 jquery 和 css 单击按钮后旋转 div 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37452477/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com