Skip to content
Related Articles

Related Articles

Web API | DOMRect fromRect property

View Discussion
Improve Article
Save Article
  • Last Updated : 12 Jul, 2022

In Web API there is a DOMRect Interface which has a property fromRect() which creates a DOMRectReadOnly object which has location and dimensions given. 

Syntax:

var domRect = DOMRectReadOnly.fromRect(DOMRect object)

Return Value:

It returns an instance of DOMRect

Example: Using fromRect. 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>DOMRect fromRect property</title>
</head>
 
<body>
    <center>
        <h1 style="color:green;">
                GeeksForGeeks
            </h1>
 
        <h2>DOMRect fromRect property</h2>
        <button onclick="getDOMRect ();">
            Get fromRect
        </button>
        <p id='DOMRect'></p>
    </center>
 
</body>
 
<script type="text/javascript">
    function getDOMRect() {
        var myDOMRect = new DOMRect(0, 0, -100, 100);
        var domRect = DOMRectReadOnly.fromRect(myDOMRect);
        console.log(domRect);
 
    }
</script>
 
</html>

Output: 

Before click the button:

  

After clicked the button:

  

Supported Browsers:

  • Google Chrome 61
  • Edge 79
  • Safari 10.1
  • Firefox 69
  • Opera 48
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!