返回js实现图片等......登陆

js实现图片等比缩放

阿神2016-11-08 11:09:31354

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

//图片等比例缩放 

<html>

<head>

<title>等比例缩放图片</title>

<script>

function DrawImage(ImgD,iwidth,iheight){   

   

    //参数(图片,允许的宽度,允许的高度)   

   

    var image=new Image();   

   

    image.src=ImgD.src;   

   

    if(image.width>0 && image.height>0){   

   

      if(image.width/image.height>= iwidth/iheight){   

   

          if(image.width>iwidth){     

   

              ImgD.width=iwidth;   

   

              ImgD.height=(image.height*iwidth)/image.width;   

   

          }else{   

   

              ImgD.width=image.width;     

   

              ImgD.height=image.height;   

   

          }   

   

      }else{   

   

          if(image.height>iheight){     

   

              ImgD.height=iheight;   

   

              ImgD.width=(image.width*iheight)/image.height;           

   

          }else{   

   

              ImgD.width=image.width;     

   

              ImgD.height=image.height;   

   

          }   

   

      }   

   

    }   

   

}  

   

</script

</head>

<body>

<img src="/images/logo.gif" alt="自动缩放后的效果" width="220" height="80" onload="javascript:DrawImage(this,100,100)" />

</body>

</html>


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送