首页>>帮助中心>>美国云服务器的html中点击图片放大怎么实现

美国云服务器的html中点击图片放大怎么实现

2023/7/17 389次

美国云服务器的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>

购买使用一诺网络美国云服务器,可以极大降低初创企业、中小企业以及个人开发者等用户群体的整体IT使用成本,无需亲自搭建基础设施、简化了运维和管理的日常工作量,使用户能够更专注于自身的业务发展和创新。美国云服务器低至49/月,购买链接:https://www.enuoidc.com/vpszq.html?typeid=3

版权声明

    声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们996811936@qq.com进行处理。