javaScript js 可滑动的div块

可以滑动的div块 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>滑动的div</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript"> var i = 0; var step = 2; var timed; var h = 0;//已经滑动的高度 function slide() { timed = setTimeout("slide()", 10); var boxHeight = document.getElementById("oBox").style.height.replace("px","");//外层div的高度 var slideBoxStyle = document.getElementById("slideBox").style; var top = slideBoxStyle.marginTop.replace("px",""); var slideBoxHeight = slideBoxStyle.height.replace("px","");//滑动div的高度 var totalHeight = Number(boxHeight) - Number(slideBoxHeight); h = Number(top) + step; if(i < 50 && h <= totalHeight) { slideBoxStyle.marginTop = h + "px"; i += step; } else { clearTimeout(timed); i = 0; } document.getElementById("show").value = h + ":" + totalHeight; } </script> </head> <body> <div id="oBox" style="width:100px;height:300px;background-color:red;overflow:hidden"> <div id="slideBox" style="width:100px;height:100px;background-color:gray;margin-top:0px"> </div> </div> <input type="button" value="Go..." οnclick="slide()"> <input type="text" id="show"> </body> </html>

转载于:https://www.cnblogs.com/javaTest/archive/2010/07/14/2589413.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值