运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> img { width: 200px; height: 400px; } </style> </head> <body> <h1>Change object-fit with JavaScript</h1> <p>Click the "Try it" button to cut off the sides of the image, preserving the aspect ratio:</p> <img src="paris.jpg" alt="Paris" id="myImg" width="400" height="300"> <br> <button onclick="myFunction()">Try it</button> <p>Note: The object-fit property is not supported in Edge 15 or earlier.</p> <script> function myFunction() { document.getElementById("myImg").style.objectFit = "cover"; } </script> </body> </html>