Computer >> 컴퓨터 >  >> 프로그램 작성 >> JavaScript

JavaScript에서 볼 수 있는 위치 지정 요소의 부분을 반환하는 방법은 무엇입니까?


위치가 지정된 요소의 어느 부분이 표시되는지 반환하려면 클립을 사용하세요. JavaScript의 속성

예시

다음 코드를 실행하여 이미지를 자르는 방법을 배울 수 있습니다. −

<!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>