Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Fabric.js getScrollLeftTop() Method

  • Last Updated : 25 May, 2021

The getScrollLeftTop() method in Fabric.js is used to find the scroll offsets of an element. The object returned by this method contains the “top” and “left” property that denotes the “top” and “left” offsets respectively. The HTML element in the page has to be selected first to pass this method.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

getScrollLeftTop(element)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • element: This parameter is used to specify the HTML element for which the scroll offsets have to be found.

Return Value: This method returns an object that contains the “top” and “left” scroll offsets as properties.



The below example demonstrates the getScrollLeftTop() method Fabric.js:

Example: 

HTML




<html>
  
<head>
    <!-- Adding the Fabric.js library -->
    <script src=
    </script>
  
    <style>
      
        /* Define the CSS classes to be used */
        .box1 {
            margin: 25px;
            width: 400px;
            height: 400px;
            background-color: red;
        }
  
        .box2 {
            margin: 25px;
            width: 700px;
            height: 300px;
            background-color: green;
        }
    </style>
</head>
  
<body>
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
  
    <h3>
        Fabric.js util.getScrollLeftTop() Method
    </h3>
      
    <div class="box1">
        Element 1
    </div>
      
    <div class="box2">
        Element 2
    </div>
  
    <script>
  
        // Select the elements to be used
        let elem =
            document.querySelector('.box1');
        let elem2 =
            document.querySelector('.box2');
  
        function getScrollOffsets() {
            console.clear();
            console.log(
                "Current Left and Top Offsets are:"
            );
  
            // Find the scrolled left and top offsets
            console.log(
                fabric.util.getScrollLeftTop(elem)
            );
            console.log(
                fabric.util.getScrollLeftTop(elem2)
            );
        }
  
        // Repeatedly call the function
        // to observe the values
        setInterval(getScrollOffsets, 1000);
    </script>
</body>
  
</html>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!