点击向下滑动, 如果要滚动的那个div的总高度,已经到边缘了 ,点击就不再滚动.....谁来帮忙修改下这个JS? O(∩_∩)O谢谢了啊。 这个JS也是一位热心的CSDN帮忙写的。<div style="width:100px;height:300px;background-color:red;overflow:hidden">
<div id="a" style="width:100px;height:100px;background-color:gray;margin-top:0px">
</div>
</div>
<input type="button" value="button" onclick="abc()">
<script type="text/javascript">
var i=0;
var sd=2;
var time;
function abc()
{
time=setTimeout("abc()",10); if(i<50)
{
document.getElementById("a").style.marginTop=document.getElementById("a").style.marginTop.replace("px","")-0+sd+"px";
i=i+sd;
}
else
{
clearTimeout(time);
i=0;
}
}
</script>
<div id="a" style="width:100px;height:100px;background-color:gray;margin-top:0px">
</div>
</div>
<input type="button" value="button" onclick="abc()">
<script type="text/javascript">
var i=0;
var sd=2;
var time;
function abc()
{
time=setTimeout("abc()",10); if(i<50)
{
document.getElementById("a").style.marginTop=document.getElementById("a").style.marginTop.replace("px","")-0+sd+"px";
i=i+sd;
}
else
{
clearTimeout(time);
i=0;
}
}
</script>
解决方案 »
- 这个代码不是抛出错误的吗》 怎么没反正的按了
- Extjs fileuploadfield获取全路径问题
- 关于JQuery中$(document).ready()函数的疑问。
- 火狐与IE下兼容问题
- 请问,在JSP前台页面中如何屏蔽F11系统键!
- 如何控制这个输入 要求14位,中间有空格, 例如:12 345 678 912
- js怎么实现三级关联
- 我想让投票完毕后弹出一个对话框.点确定后实现关闭网页高手指点了!
- 怎么用JS返回上一个历史页面
- Netscape中关于文本框的onkeypress事件的问题
- 滚动问题,在IE中不动....Firefox和opera中没事...新手求指教
- 请问一个有关FireFox起始页面的问题
<div id="a" style="width:100px;height:100px;background-color:gray;margin-top:0px">
</div>
</div>
<input type="button" value="button" onclick="abc()">
<script type="text/javascript">
var i=0;
var sd=2;
var time;
var h;function abc(){
time = setTimeout("abc()", 10);
var obj = document.getElementById("a");
h = parseInt(document.getElementById("a").style.marginTop.replace("px", "")) + sd; if(i < 50 && h + obj.offsetHeight <= obj.parentNode.offsetHeight){
document.getElementById("a").style.marginTop = h + "px";
i = i + sd;
}else{
clearTimeout(time);
i = 0;
}
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>openDiv.html</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 speed = 50;
var maxheight = 450;
//点击checkBox引发此函数
function divPopup(event, item){
var ruleDiv = document.getElementById("smsDiv");
if(item.checked){
DivShow(ruleDiv);
}else{
DivHide(ruleDiv);
}
}
//DIV展开与收起的两个函数
function DivShow(item) {
var temp = item.style.height;
item.style.height = parseInt(temp.substring(0, temp.length - 2)) + speed + "px";
temp = item.style.height;
if(parseInt(temp.substring(0, temp.length - 2)) < maxheight){
setTimeout(function () {
DivShow(item);
}, 100);
}
}
function DivHide(item) {
var temp = item.style.height;
item.style.height = parseInt(temp.substring(0, temp.length - 2)) - speed + "px";
temp = item.style.height;
temp = parseInt(temp.substring(0, temp.length - 2));
if(temp > 0){
setTimeout(function () {
DivHide(item);
}, 100);
}
}
</script>
</head>
<body>
<input type="checkbox" onclick="divPopup(event, this)"/>
<div id="smsDiv" style="border: 1px solid red; width: 200px; height: 200px; background-color: #CCCCFF;"></div>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>testFor.html</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 sd = 2;
var time;
var h = 0;
function abc() {
time = setTimeout("abc()", 10);
var boxH = document.getElementById("oBox").style.height.replace("px","");//外层div的高度
var aSty = document.getElementById("a").style;
var top = aSty.marginTop.replace("px","");
var aH = aSty.height.replace("px","");//滑动div的高度
var totalH = (Number(boxH) - Number(aH));
h = top - 0 + sd;
if(i<50 && h <= totalH) {
document.getElementById("a").style.marginTop = h + "px";
i = i + sd;
} else {
clearTimeout(time);
i = 0;
}
document.getElementById("show").value = h + ":" +totalH;
}
</script> </head>
<body>
<div id="oBox" style="width:100px;height:300px;background-color:red;overflow:hidden">
<div id="a" style="width:100px;height:100px;background-color:gray;margin-top:0px">
</div>
</div>
<input type="button" value="button" onclick="abc()">
<input type="text" id="show">
</body>
</html>
改好了