jquery - jquery中的可旋转非零角度
问题描述
这个问题与我之前的帖子Rotate the inner box as I rotate the outer box 相关。
这一次,我添加了transform:rotate(ndeg);
wheren
不等于 0。这个问题的目的是最初以n
度数旋转div 。
$(function() {
// Prepare extra handles
var nw = $("<div>", {
class: "ui-rotatable-handle"
});
var ne = nw.clone();
var se = nw.clone();
// Assign Draggable
$('.box-wrapper').draggable({
cancel: ".ui-rotatable-handle"
});
// Assign Rotatable
$('.box').rotatable({
rotate: function(event, ui) {
var angle = ui.angle.current;
$('.inner').css('transform', 'rotate(' + angle + 'rad)');
}
});
// Assign coordinate classes to handles
$('.box div.ui-rotatable-handle').addClass("ui-rotatable-handle-sw");
nw.addClass("ui-rotatable-handle-nw");
ne.addClass("ui-rotatable-handle-ne");
se.addClass("ui-rotatable-handle-se");
// Assign handles to box
$(".box").append(nw, ne, se);
// Assigning bindings for rotation event
$(".box div[class*='ui-rotatable-handle-']").bind("mousedown", function(e) {
$('.box').rotatable("instance").startRotate(e);
});
});
.box {
border: 2px solid black;
width: 100px;
height: 100px;
background: transparent;
margin: 40px;
position: absolute;
transform: rotate(315deg);
}
.inner {
background: red;
width: 70px;
height: 70px;
position: absolute;
top: 57px;
left: 57px;
transform: rotate(315deg);
}
.ui-rotatable-handle {
background: url("https://cdn.jsdelivr.net/jquery.ui.rotatable/1.0.1/rotate.png");
background-repeat: no-repeat;
background-size: 100% 100%;
height: 25px;
width: 25px;
position: absolute;
}
.ui-rotatable-handle-sw {
bottom: -27px;
left: -27px;
}
.ui-rotatable-handle-nw {
top: -27px;
left: -27px;
}
.ui-rotatable-handle-se {
bottom: -27px;
right: -27px;
}
.ui-rotatable-handle-ne {
top: -27px;
right: -27px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/jquery.ui.rotatable/1.0.1/jquery.ui.rotatable.min.js"></script>
<div class="box-wrapper">
<div class="inner">
RED BOX
</div>
<div class="box">
</div>
</div>
这是完整的代码https://jsfiddle.net/pknwe954/1/
注意:HTML 的结构应该和原来的一样,所以不需要改变它。
问题:如何修复n
度数上的可旋转 div?
解决方案
推荐阅读
- git - 有没有办法告诉 git 哪些行在差异中被视为已修改?
- laravel - Laravel:如何根据某些条件隐藏数据?
- vim - 使用“EAGAIN(资源暂时不可用)”回溯打开文件时,Vim 卡住了
- html - ReactJS 链接到来自不同文件夹/项目的本地 HTML 文件
- python - TypeError:'int'对象不可下标python
- powershell - 在 Visual Studio Code 中,使用 Connect-AzAccount 登录 Azure 时,PowerShell 一直挂起
- apache-spark - google dataproc - 图像版本 2.0.x 如何将 pyspark 版本降级到 3.0.1
- javascript - 极端新手在 mousePressed() 事件方面需要帮助
- javascript - JS.elseif (audio2.play()) { audio2.muted}
- javascript - 在 React 中将字符串解析为导入的对象变量名