1
내 코드에서 알아낼 수없는 수학 문제가 있습니다.회전 각도 계산 문제
빨간 동그라미 중 하나를 누르면 가장 가까운 경로 (왼쪽 또는 오른쪽)로 내려 가서 아래로 회전합니다. 다소 효과가 있지만 몇 가지 문제가 있습니다.
'8'을 누른 다음 '3'을 눌러 시작하면 컨테이너가 잘못된 방향으로 45 도만 회전합니다.
그리고 두 번째 문제는 휠이 회전 할 때 숫자가 돌아가고 있다는 것입니다. 주어진 각도하여 요소를 회전하려고하는 동안 https://jsfiddle.net/she4x2w6/10/
$('.item').click(function() {
var currentId = $('#container').data('id');
var nextId = $(this).data('id');
var currentRotation = (360/items.length) * currentId - (360/items.length);
var nextRotation = (360/items.length) * nextId - (360/items.length);
var deg;
if (currentRotation - nextRotation > 180 || nextRotation - currentRotation > 180) {
deg = nextRotation > 180 ? 360 - nextRotation : nextRotation - 360;
} else {
deg = -Math.abs(nextRotation);
}
var itemDeg = nextRotation <= 180 ? nextRotation : -Math.abs(360 - nextRotation);
$('#container').css({
transition: 'transform 0.6s',
transform: 'rotate(' + deg + 'deg)'
})
$('.item').css({
transition: 'transform 0.6s',
transform: 'rotate(' + itemDeg + 'deg)'
})
멋진 일을 :
rotate() -CSS | MDN
나는이 작업을 얻을 당신의 접근 방식의 일부를 변경했다! 감사! – qua1ity