Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> JavaScript

วิธีคืนค่าส่วนที่มองเห็นขององค์ประกอบที่จัดตำแหน่งใน JavaScript


หากต้องการคืนค่าส่วนที่มองเห็นขององค์ประกอบที่จัดตำแหน่ง ให้ใช้คุณสมบัติ clip ใน 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>