JavaScript dynamically scales the images on the web page to fit the screen size as needed

From , 5 Years ago, written in JavaScript, viewed 128 times.
URL https://pastebin.vip/view/82356b37
  1. <html>
  2. <head>
  3. <title>JavaScript等比例缩放图片</title>
  4. <script>
  5. function DrawImage(ImgD,iwidth,iheight){ //参数(图片,允许的宽度,允许的高度)
  6. var image=new Image();
  7. image.src=ImgD.src;
  8. if(image.width>0
  9. && image.height>0){ if(image.width/image.height >= iwidth / iheight)
  10. {
  11.     if (image.width > iwidth) {
  12.         ImgD.width = iwidth;
  13.         ImgD.height = (image.height * iwidth) / image.width;
  14.     }
  15.     else {
  16.         ImgD.width = image.width;
  17.         ImgD.height = image.height;
  18.     }
  19. }
  20. else
  21. {
  22.     if (image.height > iheight) {
  23.         ImgD.height = iheight;
  24.         ImgD.width = (image.width * iheight) / image.height;
  25.     }
  26.     else {
  27.         ImgD.width = image.width;
  28.         ImgD.height = image.height;
  29.     }
  30. }
  31. }
  32. }
  33.  </script>
  34. </head>
  35. < body>
  36. <img src="http://www.haotu.net/up/2013/08/02/137540300905687.jpg"  alt="图片自动缩放" width = "100" height = "100" onload="javascript:DrawImage(this,80,80)" />
  37. </body></html>
  38. //javascript/8315

Reply to "JavaScript dynamically scales the images on the web page to fit the screen size as needed"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website