溫馨提示×

html中點擊圖片放大怎么實現

清風
13343
2021-03-26 19:00:06
欄目: 編程語言

html中點擊圖片放大的實現方法:1.創建一個html文件;2.在html文件中添加html代碼架構;3.在body標簽里面使用img標簽添加一張圖片以及使用script標簽添加函數實現鼠標點擊圖片放大的效果;4.通過瀏覽器方式查看設置效果。

html中點擊圖片放大怎么實現

html中點擊圖片放大的實現方法:

1.首先創建一個html文件。

2.在html文件中添加html代碼架構。

<!DOCTYPE html>

<html>

    <head>

        <title>圖片放大</title>

    </head>

    <body>

    </body>

</html>

3.然后在html代碼架構中的body標簽里面使用img標簽添加一張圖片以及使用script標簽添加一個函數實現鼠標點擊圖片放大的效果。

<div style=" width:300px; height:300px;margin-left:auto; 

        margin-right:auto; overflow:hidden; margin-top:100px;">       

        <img id="img" onmouseover="bigger()" onmouseout="smaller()"         

        src="http://mat1.gtimg.com/www/images/qq2012/guanjia2.png"         

        style="cursor:pointer;width:300px;height:300px;      

        transition:all 1s ease-out 0s; perspective-origin:bottom;"/>      

        <script type="text/javascript">       

        var img = document.getElementById('img');        

        function bigger(){        

        img.style.width = '400px';        

        img.style.height = '400px';        

        img.style.marginTop = "-50px";        

        img.style.marginLeft = "-50px";        

        }        

        function smaller(){

        img.style.width = '300px';        

        img.style.height = '300px';        

        img.style.marginTop = "0px";        

        img.style.marginLeft = "0px"; 

        }       

        </script>

4.最后可通過瀏覽器方式閱讀html文件查看設計效果。

完整示例代碼如下:

<!DOCTYPE html>

<html>

    <head>

        <title>圖片放大</title>

    </head>

    <body>

        <div style=" width:300px; height:300px;margin-left:auto; 

        margin-right:auto; overflow:hidden; margin-top:100px;">

        <img id="img" onmouseover="bigger()" onmouseout="smaller()" 

        src="http://mat1.gtimg.com/www/images/qq2012/guanjia2.png" 

        style="cursor:pointer;width:300px;height:300px; 

        transition:all 1s ease-out 0s; perspective-origin:bottom;"/>

        <script type="text/javascript">

        var img = document.getElementById('img');

        function bigger(){

        img.style.width = '400px';

        img.style.height = '400px';

        img.style.marginTop = "-50px";

        img.style.marginLeft = "-50px";

        }

        function smaller(){

        img.style.width = '300px';

        img.style.height = '300px';

        img.style.marginTop = "0px";

        img.style.marginLeft = "0px";

        }

        </script>

    </body>

</html>

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女