How to return which part of a positioned element is visible in JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To return which part of a positioned element is visible, use the clip property in JavaScript.

Example

You can try to run the following code to learn how to clip an image −

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         img {
            position: absolute;
            top: 100px;
         }
      </style>
   </head>
   <body>
      <button type="button" onclick="display()">Clip</button><br>
      <img id="newImg" src="https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg" width="170" height="150">
      <script>
         function display() {
            document.getElementById("newImg").style.clip = "rect(10px 90px 90px 10px)";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 14:54:52
Advertisements