【发布时间】:2017-11-22 06:42:46
【问题描述】:
我的小提琴链接here
<body>
<div>
<div id="wrapper" style="">
<div id="container">
<div class="handles">
<span data-clickable="true" id="rotate-handle"></span>
</div>
</div>
<div id="item_1" class="item" style=""></div>
<div id="item_2" class="item" style=""></div>
<div id="item_3" class="item" style=""></div>
</div>
</div>
</body>
function rotateStart(e) {
startAngle = Math.atan2(e.clientX - contatiner_x + contatiner_width / 2, - (e.clientY - container_y + container_height / 2) )*(180/Math.PI);
window.addEventListener('mousemove', rotate, false);
window.addEventListener('mouseup', rotateStop, false);
}
function rotate(e) {
var angle = Math.atan2(e.clientX - contatiner_x + contatiner_width / 2, - (e.clientY - container_y + container_height / 2) )*(180/Math.PI);
var rotate_angle = angle - startAngle;
contatier.style.transform = 'translate(50px, 100px) rotateZ('+rotate_angle+'deg)';
}
function rotateStop() {
window.removeEventListener('mousemove', rotate, false);
}
我正在研究它只是为了实验。 我只想旋转所有项目以及没有变换原点的容器。
PS : 通过右上角的手柄旋转容器, 容器和项目是兄弟姐妹。
【问题讨论】:
-
需要将物品放入容器jsfiddle.net/p21bg5pb/1
-
"没有变换原点" 不可能,总是围绕变换原点进行旋转。不过,您可以计算与原点相关的“偏移量”。
标签: javascript rotation trigonometry