zoukankan      html  css  js  c++  java
  • JS---改变图片大小

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>改变图片大小  方法1</title>
        <script>
            function showbigger(){
                var div=document.getElementById("div");
                div.style.width=500+"px";
                div.style.height=500+"px";
            }
            function showsmaller(){
                var div=document.getElementById("div");
                div.style.width=100+"px";
                div.style.height=100+"px";   //注意获取的ID时img的ID
            }
    
        </script>
    </head>
    <body>
        <button  onclick="showbigger()">放大</button>
        <button  onclick="showsmaller()">缩小</button>
        <div style=" 100px;height: 100px"><img src='img/1.jpg' id="div" ></div>
    </body>
    </html>

    方法2:

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>图片放大缩小</title>
    </head>
    <body>
        <p align="center">
            <input type="button" value="放大" onclick="blowup()">
            <input type="button" value="缩小" onclick="reduce()">
        </p>
        <table width="300" border="0" align="center">
            <tr>
                <td>
                    <div align="center">
                        <input name="img" type="image" id="img" src="1.jpg" align="middle" border="0">
                    </div>
                </td>
            </tr>
        </table>
        <p>
            <script language="JavaScript">
                function blowup(){
                    var height=img.height;
                    var width=img.width;
                    if((height<=height*2)||(width<=width*2)){  //可以无限放大
                        img.height=img.height+20;
                        img.width=img.width+20;
                    }
                }
                function reduce(){
                    if((img.height>100)||(img.width>100)){   //可以缩小到宽或者高等于100px时的大小
                        img.height=img.height-20;
                        img.width=img.width-20;
                    }
                }
            </script>
        </p>
    <div align="center"></div>
    <p>&nbsp;</p>
    </body>
    </html>
  • 相关阅读:
    解题报告 poj 1486
    解题报告 比赛
    解题报告 keke 的房子
    解题报告 Tree
    解题报告 聚会
    解题报告 Valentine‘s seat
    解题报告 报数
    解题报告 黑书 Water pail poi 1999
    解题报告 poj 1639
    解题报告 数数
  • 原文地址:https://www.cnblogs.com/Andy-/p/7596103.html
Copyright © 2011-2022 走看看