The perspectiveOrigin
property defines where a 3D
element is based in the x- and the y-axis.
We can use this property to change the bottom position of 3D elements.
perspectiveOrigin |
Yes (WebkitPerspecitveOrigin) | 10 | Yes | Yes (WebkitPerspecitveOrigin) | Yes (WebkitPerspecitveOrigin) |
Return the perspectiveOrigin property:
var v = object.style.perspectiveOrigin;
Set the perspectiveOrigin property:
object.style.perspectiveOrigin='x-axis y-axis|initial|inherit'
Value | Description |
---|---|
x-axis | where to place the view at the x-axis Possible values:
Default value: 50% |
y-axis | where to place the view at the y-axis Possible values:
Default value: 50% |
initial | Set to default value |
inherit | Inherit from parent element. |
Default Value: | 50% 50% |
---|---|
Return Value: | A string representing the perspective-origin property of an element |
CSS Version | CSS3 |
The following code shows how to set a 3D element's base placement.
<!DOCTYPE html>
<html>
<head>
<style>
#div1 {<!--from ww w .j a va2s . co m-->
position: relative;
margin: auto;
height: 150px;
width: 250px;
padding: 10px;
border: 1px solid black;
-webkit-perspective: 125px; /* Chrome, Safari, Opera */
perspective: 125px;
}
#div2 {
padding: 50px;
position: absolute;
border: 1px solid black;
background-color: coral;
-webkit-transform: rotateX(45deg); /* Chrome, Safari, Opera */
transform: rotateX(45deg);
}
</style>
</head>
<body>
<button onclick="myFunction()">test</button>
<div id="div1">DIV1<div id="div2">test!</div></div>
<script>
function myFunction() {
document.getElementById("div1").style.WebkitPerspectiveOrigin = "10px 50%"; // Chrome, Safari and Opera
document.getElementById("div1").style.perspectiveOrigin = "10px 50%";
}
</script>
</body>
</html>
The code above is rendered as follows: