用js实现的一个小程序(对一块区域的放大,缩小)

本文介绍如何使用CSS和JavaScript来实现网页元素的动态放大效果。通过设置元素的初始位置、尺寸和边界,结合鼠标悬停事件,调整元素宽度、高度及背景颜色,实现交互式的视觉变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//css

<style type="text/css">

#enlarge1{position:absolute;width:100px; height:100px; border:1px solid #000;}
#enlarge2{position:absolute; top:100px; width:100px; height:200px ;margin-top:20px; border:1px solid #000; }
#enlarge3{position:absolute; top:10px; left:110px;width:200px; height:312px; margin-left:10px; margin-top:-2px; border:1px solid #000; }
</style>

//html

<div id="enlarge1"></div>
<div id="enlarge2"></div>
<div id="enlarge3"></div>

//js

<script type="text/javascript">
function enlargeFc(id,x,y){
var option=document.getElementById(id);
var optionWidth=option.clientWidth;
var optionHeight=option.clientHeight;

option.onmouseover=function(){
this.style.width=optionWidth*x+"px";
this.style.height=optionHeight*y+"px";
this.style.background="#0f0";
this.style.zIndex=100000;
}
option.onmouseout=function(){
this.style.width=optionWidth+"px";
this.style.height=optionHeight+"px";
this.style.background="";
this.style.zIndex="auto";
}

}
enlargeFc("enlarge2",1,1);
</script>

//效果

转载于:https://www.cnblogs.com/fangdx/p/3645386.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值