html页面里面如何实现点击小图放大查看大图

html页面里面如何实现点击小图放大查看大图,第1张

需要准备的材料分别有:电脑、浏览器、html编辑器

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<style>标签中,输入css代码

div {width: 72pxheight: 72pxbackground: url(small3.png) no-repeatoverflow: hidden}

3、浏览器运行index.html页面,此时成功将矩形图片只显示了正方形部分。

4、点击小图后,成功显示了大图。

html中图片以中心放大的代码如下:

<div style=" width:300px height:300pxmargin-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:pointerwidth:300pxheight: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>

扩展资料:

在html中用js实现鼠标指向图片时图片放大的效果的代码如下:

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

src="你的图片路径" style="width:100pxheight:100px" />

<script type="text/javascript">

var img = document.getElementById('img')

function bigger(){  img.style.width = '400px'  img.style.height = '400px' }

function smaller(){  img.style.width = '100px'  img.style.height = '100px' }

</script>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6296538.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-20
下一篇 2023-03-20

发表评论

登录后才能评论

评论列表(0条)

保存