Javascript upload the picture to achieve a proportional scaling and display intact

Related Tags:

  We often encountered in the pages of the photos in accordance with the size of our own to show that this will give some pages appear more standardized.    For example, we have to show in the pages of 130 × 160 pictures, we will be equivalent to a picture frame Add to this that, over the zoom on the size of this box, as it stood on a small display.    We have here two kinds of solutions, 
  1, in accordance with the proportion of the zoom 
  <script Language="javascript"> 
  Function changeImg (mypic) ( 
  Var xw = 130; 
  Var xl = 160; 

  Var Width = mypic.width; 
  Var Height = mypic.height; 

  If (width> xw) mypic.width = xw; 
  If (height> xl) mypic.height = xl; 
  ) 
  </ Script> 
  <img Src="sh180.jpg" onload="changeImg(this)"> 2, in accordance with the proportion of the zoom 
  <script Language="javascript"> 
  Function changeImg1 (mypic) ( 
  Var xw = 160; 
  Var xl = 180; 

  Var width = mypic.width; 
  Var height = mypic.height; 
  Var bili = width / height; 

  Var A = xw / width; 
  Var B = xl / height; 

  If (A> 1 | | B> 1) 
  ( 
  If (A <B) 
  ( 
  Mypic.width = xw; 
  Mypic.height = xw / bili; 
  ) 
  If (A> B) 
  ( 
  * = Xl mypic.width bili; 
  Mypic.height = xl; 
  ) 
  ) 
  ) 
  </ Script> 
  <img Src="sh180.jpg" onload="changeImg(this)"> 

Related articles:

Recommended reading Concise Guide to HTML
  "Hypertext markup language" Concise Seeker (Chinese version)    (This article applies to all browsers)    Connecting to the Internet network, in the colorful WWW browser's home page, for the average user has no stranger, how to prepare their own home pages...
CSS and C # in div automatically completed another Flooding
  <div Id="main">    <div Id="div1" onclick="clickfun();" />    <div Id="div2" onclick="clickfun2();"> </ div>    </ Div>    <! - This way, unable to form a wide div1 ...
CSS how to achieve effective alternative picture
  CSS how to achieve effective alternative picture    (# Newone    Display: block;    Padding: 0;    Margin: 0;    Background: url (/ newone.gif) no-repeat;    Width: 40px;    Height: 20px;    )  &nbs...
Performance affinity sites: Let your website for public lover
  It is the popularity of the personal homepage, as long as the Internet, will shuttle people in the streets and alleys of the Internet.    It is undeniable that these sites are good everywhere, but not worth mentioning site is not uncommon.    Clearly, whether or Netizen s...
Flash ActionScript 3.0 tutorial series
  The author's blog: www.kingda.org    ActionScript 3.0 tutorial series (1): Flash9 first come first intimate contact!    Flash Professional 9 ActionScript 3.0 Preview version released today, and the subsequent we not only from the use of Flex 2 to use AS3.0, but also...