Open In App

HTML | DOM Style perspectiveOrigin Property

The perspectiveOrigin property in HTML DOM is used to describe the exact position of a 3D element based on the x and y-axis. This property has the facility to change the bottom position of 3D elements. The perspectiveOrigin property defines an element, it is child elements that are actually positioned, not the absolute parent element itself. 

Syntax:



object.style.perspectiveOrigin
object.style.perspectiveOrigin = "x-axis y-axis|initial|inherit"

Return Values: It returns a string value that represents the perspective-origin property of an element

Property Values:



Example 1: It is used to set the DOM style perspectiveOrigin property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Style perspectiveOrigin Property
    </title>
 
    <style>
        #box1 {
            margin-left: 100px;
            height: 150px;
            width: 100px;
            border: 5px solid green;
             
            /* For Chrome, Safari, Opera browsers */
            -webkit-perspective: 150px;
            perspective: 150px;
        }
         
        #box2 {
            padding: 50px;
            position: absolute;
            border: 1px solid yellow;
            background-color: green;
             
            /* For Chrome, Safari, Opera browsers */
            -webkit-transform: rotateX(80deg);
            transform: rotateX(80deg);
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
     
    <h2>
        HTML DOM Style perspectiveOrigin Property
    </h2>
     
    <p>
        Click the button to change the
        perspecive-origin property
    </p>
 
    <button onclick="myGeeks()">
        Click Here!
    </button>
 
    <div id="box1">GeeksforGeeks
        <div id="box2">
            A computer science portal for geeks
        </div>
    </div>
 
    <!-- script to set perspectiveOrigin property -->
    <script>
        function myGeeks() {
             
            // For Chrome, Safari and Opera browsers
            document.getElementById("box1").style.WebkitPerspectiveOrigin
                    = "30px 10%";
                     
            document.getElementById("box1").style.perspectiveOrigin
                    = "30px 10%";
        }
    </script>
</body>
 
</html>                               

Output: 

Before Click on the button:

  

After Click on the button:

  

Example 2: It is used to set the DOM style perspectiveOrigin property. 




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM Style perspectiveOrigin Property
    </title>
     
    <style>
        #div1 {
            margin-left:100px;
            height: 100px;
            width: 100px;
            border: 5px solid green;
             
            /* For Chrome, Safari and Opera browsers */
            -webkit-perspective: 25px;
            perspective: 25px;
        }
         
        #div2 {
            padding: 30px;
            position: absolute;
            border: 1px solid yellow;
            background-color: green;
             
            /* For Chrome, Safari and Opera browsers */
            -webkit-transform: rotateX(75deg);
            transform: rotateX(75deg);
        }
    </style>
 
    <body>
        <h1>GeeksforGeeks</h1>
         
        <h2>
            HTML DOM Style perspectiveOrigin Property
        </h2>
         
        <p>
            Click the button to change the
            perspecive-origin property
        </p>
 
        <button onclick="myGeeks()">Click Here!</button>
 
        <div id="div1">GeeksforGeeks
            <div id="div2">
                A computer science portal for geeks
            </div>
        </div>
         
        <script>
         
        function myGeeks() {
             
            /* For Chrome, Safari and Opera browsers */
            document.getElementById("div1").style.WebkitPerspectiveOrigin
                    = "30% 70%";
                     
            document.getElementById("div1").style.perspectiveOrigin
                    = "30% 70%";
        }
    </script>
</body>
 
</html>                   

Output: 

Before click on the button:

  

After click on the button:

  

Supported Browsers: The browsers supported by DOM Style perspectiveOrigin property are listed below:


Article Tags :