<header>
<h2 class="title">element.style.perspectiveOrigin</h2>
<p class="description">Визначає початкову точку перспективи для 3D-трансформацій відносно елемента.</p>
</header>
<main>
<div class="result">
<div id="perspective-control">
<label for="perspectiveOriginX">Перспектива по горизонталі: <span id="perspectiveOriginXValue">50%</span></label>
<input type="range" id="perspectiveOriginX" min="0" max="100" value="50">
<br>
<label for="perspectiveOriginY">Перспектива по вертикалі: <span id="perspectiveOriginYValue">50%</span></label>
<input type="range" id="perspectiveOriginY" min="0" max="100" value="50">
</div>
<div id="cube-container">
<div id="cube">
<div class="face front">Front</div>
<div class="face back">Back</div>
<div class="face left">Left</div>
<div class="face right">Right</div>
<div class="face top">Top</div>
<div class="face bottom">Bottom</div>
</div>
</div>
</div>
</main>
body {
font-size: 16px;
line-height: 1.5;
font-family: monospace;
}
header {
background-color: #f1f1f1;
margin-bottom: 25px;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
header h2.title {
padding-bottom: 15px;
border-bottom: 1px solid #999;
}
header p.description {
font-style: italic;
color: #222;
}
.result {
background-color: #f8f8f8;
padding: 15px;
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
box-shadow: 0px 0px 3px 0px rgba(118, 118, 118, 1);
}
#perspective-control {
margin-bottom: 15px;
}
#cube-container {
perspective: 800px;
width: 200px;
height: 200px;
margin: 0 auto;
}
#cube {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
animation: rotate 10s infinite linear;
}
.face {
position: absolute;
width: 200px;
height: 200px;
background-color: rgba(255, 255, 255, 0.9);
border: 1px solid #ccc;
text-align: center;
line-height: 200px;
font-size: 20px;
color: #333;
margin-top: 75px;
}
.front { transform: translateZ(100px); }
.back { transform: rotateY(180deg) translateZ(100px); }
.left { transform: rotateY(-90deg) translateZ(100px); }
.right { transform: rotateY(90deg) translateZ(100px); }
.top { transform: rotateX(90deg) translateZ(100px); }
.bottom { transform: rotateX(-90deg) translateZ(100px); }
@keyframes rotate {
from { transform: rotateX(30deg) rotateY(30deg); }
to { transform: rotateX(30deg) rotateY(390deg); }
}
const perspectiveOriginX = document.getElementById('perspectiveOriginX');
const perspectiveOriginY = document.getElementById('perspectiveOriginY');
const perspectiveOriginXValue = document.getElementById('perspectiveOriginXValue');
const perspectiveOriginYValue = document.getElementById('perspectiveOriginYValue');
const cubeContainer = document.getElementById('cube-container');
perspectiveOriginX.addEventListener('input', function() {
const xValue = perspectiveOriginX.value + '%';
perspectiveOriginXValue.textContent = xValue;
updatePerspectiveOrigin();
});
perspectiveOriginY.addEventListener('input', function() {
const yValue = perspectiveOriginY.value + '%';
perspectiveOriginYValue.textContent = yValue;
updatePerspectiveOrigin();
});
function updatePerspectiveOrigin() {
const xValue = perspectiveOriginX.value + '%';
const yValue = perspectiveOriginY.value + '%';
cubeContainer.style.perspectiveOrigin = `${xValue} ${yValue}`;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.