I'm having quite a bit of trouble with this, and after working tirelessly on it I've decided to just post my problem on here. My boss wants me to figure out a problem with his org-board. The problem arises when the user wants to move from division 6 to division 7--instead of it going anti-clockwise to division 7, it rotates all the way back to division 6 going clockwise. I understand why it's doing this, but I haven't figured out how to make it go anti-clockwise to the next panel without having it rotate all the way back to division 7. I have a CodePen for it, figured it would be easier than posting a ton of code on here: https://codepen.io/jamesaluna/pen/gNRWNJ . If you're not quite sure what I'm trying to exactly do please ask me, thank you!
I tried creating an 'm' variable that calculated the amount of rotations, but that hasn't done much good. I also put the elements in an array and fiddled around with that a bit, using a for/in loop, but I have yet to figure out a solution using that.
var carousel = document.querySelector('.carousel');
var cellCount = 7;
var selectedIndex = 1;
function rotateCarousel() {
var angle = selectedIndex / cellCount * -360;
carousel.style.transform = 'translateZ(-898px) rotateY(' + angle + 'deg)';
}
rotateCarousel();
var sevenButton = document.querySelector('.seven-button');
sevenButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 1;
if (selectedIndex == 7) {
selectedIndex = 1 ;
}
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var oneButton = document.querySelector('.one-button');
oneButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 2;
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var twoButton = document.querySelector('.two-button');
twoButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 3;
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var threeButton = document.querySelector('.three-button');
threeButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 4;
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var fourButton = document.querySelector('.four-button');
fourButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 5;
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var fiveButton = document.querySelector('.five-button');
fiveButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 6;
rotateCarousel();
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
var sixButton = document.querySelector('.six-button');
sixButton.addEventListener( 'click', function() {
var m = Math.floor(selectedIndex / cellCount);
selectedIndex = m + 7;
rotateCarousel();
if (selectedIndex == 7) {
selectedIndex = 6 ;
}
document.getElementById("demo").innerHTML = m;
document.getElementById("demo2").innerHTML = selectedIndex;
});
``` CSS
.carousel__cell:nth-child(7n+3) { background: hsla( 360, 100%, 100%, 1); border: 2px solid #B754F7;}
.carousel__cell:nth-child(7n+4) { background: hsla( 360, 100%, 100%, 1);border: 2px solid #FF91FF; }
.carousel__cell:nth-child(7n+5) { background: hsla( 360, 100%, 100%, 1);border: 2px solid #009C00; }
.carousel__cell:nth-child(7n+6) { background: hsla( 360, 100%, 100%, 1);border: 2px solid #999; }
.carousel__cell:nth-child(7n+7) { background: hsla( 360, 100%, 100%, 1);border: 2px solid #FFED8A; }
.carousel__cell:nth-child(7n+1) { background: hsla( 360, 100%, 100%, 1); border: 2px solid #3A43F9; }
.carousel__cell:nth-child(7n+2) { background: hsla( 360, 100%, 100%, 1); border: 2px solid #F4D100; }
.carousel__cell:nth-child(7) { transform: rotateY( 0deg) translateZ(1030px); }
.carousel__cell:nth-child(1) { transform: rotateY( 51.428deg) translateZ(1030px); }
.carousel__cell:nth-child(2) { transform: rotateY(102.856deg) translateZ(1030px); }
.carousel__cell:nth-child(3) { transform: rotateY(154.284deg) translateZ(1030px); }
.carousel__cell:nth-child(4) { transform: rotateY(205.712deg) translateZ(1030px); }
.carousel__cell:nth-child(5) { transform: rotateY(257.14deg) translateZ(1030px); }
.carousel__cell:nth-child(6) { transform: rotateY(308.568deg) translateZ(1030px); }