html某个模块移动,【图片】【JS】有关div收缩和模块移动【it发烧友吧】_百度贴吧...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

HTML+JS:

动画效果制作

#dv1{

width:400px;

height:100px;

border:1px solid blue;

}

#dv2{

width:100px;

height:100px;

background-color:red;

position:absolute;

top:135px;

}

var get=function(id){

return document.getElementById(id);

};

οnlοad=function(){

var btn1=get("btn1");

var dv1=get("dv1");

btn1.οnclick=function(){

var recId1=setInterval(

function(){

var width=parseInt(dv1.style.width||dv1.offsetWidth);

var p=Math.ceil(width/10);

width=width-p;

if(width<=0){

clearInterval(recId1);

dv1.style.display="none";

}

dv1.style.width=width+"px";}

,20);

};

var btn2=get("btn2");//这个获取值必须写在onload里面,不然获取到的值为null

var dv2=get("dv2");

btn2.οnclick=function(){

var recId2=setInterval(

function(){ //这里千万要注意定义函数

var curX=parseInt(dv2.style.left||dv2.offsetLeft);

var p=Math.ceil((800-curX)/10);

curX=curX+p;

if(curX>=800){

clearInterval(recId2);

}

dv2.style.left=curX;

}

,20);

};

};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值