Linux 拨号vps windows公众号手机端

html中点击图片放大怎么实现

lewis 6年前 (2019-04-01) 阅读数 12 #程序编程
文章标签 html

html中点击图片放大的实现方法:1.创建一个html文件;2.在html文件中添加html代码架构;3.在body标签里面使用img标签添加一张图片以及使用script标签添加函数实现鼠标点击图片放大的效果;4.通过浏览器方式查看设置效果。

html中点击图片放大的实现方法:

1.首先创建一个html文件。

2.在html文件中添加html代码架构。

<!DOCTYPEhtml>

<html>

<head>

<title>图片放大</title>

</head>

<body>

</body>

</html>

3.然后在html代码架构中的body标签里面使用img标签添加一张图片以及使用script标签添加一个函数实现鼠标点击图片放大的效果。

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

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

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

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

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

transition:all1sease-out0s;perspective-origin:bottom;"/>

<scripttype="text/javascript">

varimg=document.getElementById('img');

functionbigger(){

img.style.width='400px';

img.style.height='400px';

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

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

}

functionsmaller(){

img.style.width='300px';

img.style.height='300px';

img.style.marginTop="0px";

img.style.marginLeft="0px";

}

</script>

4.最后可通过浏览器方式阅读html文件查看设计效果。

完整示例代码如下:

<!DOCTYPEhtml>

<html>

<head>

<title>图片放大</title>

</head>

<body>

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

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

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

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

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

transition:all1sease-out0s;perspective-origin:bottom;"/>

<scripttype="text/javascript">

varimg=document.getElementById('img');

functionbigger(){

img.style.width='400px';

img.style.height='400px';

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

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

}

functionsmaller(){

img.style.width='300px';

img.style.height='300px';

img.style.marginTop="0px";

img.style.marginLeft="0px";

}

</script>

</body>

</html>

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门