2016-07-13 2 views
0

다양한 소스를 사용하여 회전식 작업을하고 있습니다. 지금 작업 데모가 있지만 회전 목마 안에있는 항목의 양을 변경하면 크기가 변경된다는 것을 알지 못합니다.동적 CSS 캐 러셀 크기가 변경됩니다.

누군가가 내게 무슨 일이 일어 났는지 설명 할 수 있습니까? 더 자세히 축소 된 것처럼 보입니다.

http://codepen.io/sereal_killer/pen/zBPJAj

CSS :

.container-window { 
    top: 0px; 
    padding: 0px; 
    height: 170px; 
    border: 1px solid red; 
    position: relative; 
    width: 300px; 
    overflow: hidden; 
    margin: auto; 
} 

.container { 
    top: 15px; 
    margin: 0 auto; 
    width: 210px; 
    height: 140px; 
    position: relative; 
    perspective: 1000px; 
} 

#carousel { 
    width: 100%; 
    height: 100%; 
    position: absolute; 
    transform-style: preserve-3d; 
    transition: transform 1s; 
} 

#carousel .item{ 
    margin: 0 auto; 
    display: block; 
    position: absolute; 
    width: 206px; 
    height: 116px; 
    left:0px; 
    top: 10px; 
    border: 2px solid black; 
    text-align:center; 
    background-color:grey; 
} 

.next, .prev { 
    color: #444; 
    position: absolute; 
    top: 100px; 
    padding: 1em 2em; 
    cursor: pointer; 
    background: #CCC; 
    border-radius: 5px; 
    border-top: 1px solid #FFF; 
    box-shadow: 0 5px 0 #999; 
    transition: box-shadow 0.1s, top 0.1s; 
} 

.next:hover, .prev:hover { color: #000; } 
.next:active, .prev:active { 
    top: 100px; 
    box-shadow: 0 1px 0 #999; 
} 


.next { right: 5em; } 
.prev { left: 5em; } 

JS

var carousel = document.getElementById("carousel") 
var currdeg = 0; 

var prev = document.getElementsByClassName("prev"); 
var next = document.getElementsByClassName("next"); 

var items = document.getElementsByClassName("item"); 
var degreeToRotate = 360/items.length 

var tz = Math.round((items[0].offsetWidth/2)/
    Math.tan(((Math.PI * 2)/items.length)/2)); 

next[0].addEventListener("click", function() { rotate("n") }); 
prev[0].addEventListener("click", function() { rotate("p") }); 

//$(".next").on("click", { d: "n" }, rotate); 
//$(".prev").on("click", { d: "p" }, rotate); 

setItemPos(); 

function setItemPos() { 
    for (var i = 0; i < items.length; i++) { 
     items[i].style.transform = "rotateY(" + (i*degreeToRotate) + "deg) translateZ(" + tz + "px)"; 
    } 
} 


console.log(degreeToRotate); 
function rotate(e) { 
    if (e == "n") { 
     currdeg = currdeg - degreeToRotate; 
    } 
    if (e == "p") { 
     currdeg = currdeg + degreeToRotate; 
    } 

    carousel.style.transform = "rotateY(" + currdeg + "deg)"; 
    console.log("degree:" + currdeg); 
} 
+0

아마 카메라에 가까워 졌을까요? –

+0

그래, 지금은 많이 생각했는데 어떻게 조정해야할지 모르겠다. 회전 지점을 더 멀리 움직이거나 카메라를 가까이에 두는 방법은 내가 찾고있는 것이지만 나는 아직 이것을 이해하지 못한다. – JSB

답변

0

내가 4 개 항목 추측이 회전 목마에 대한 완벽한, 더 때문에 각면의 회전의 시각적 인 변화를 만들 것입니다.

+0

하지만 회전과 번역은 동적으로 완료됩니다. 왜 축소되는지 이해하지 못합니다. 내가 아이템을 추가 할 때 아이템을 제거하거나 줌인 할 때 – JSB

+0

네, 회전 속성이 항목 위치 지정에 이상한 변화를하고 있다고 생각합니다. 더 많은면을 가지고 있기 때문에 회전식 오브젝트가 넓어지고 앞면이 가까이 보입니다. 우리에게. –

+0

흠. 이 튜토리얼을 사용하여 부분적으로 빌드합니다 : https : //desandro.github.io/3dtransforms/docs/carousel.html 그러나 그의 예제는 잘 작동하는 것 같습니다. 나는 내가 다른 것을하고 있는지 알아 내기 위해 코드를 다시 살펴볼 것이다. – JSB