Chumbir
2017-10-12 14:26请问为什么js滚动滚动条到顶部之后就不能动了?
第二次发生过这种情况,js或者jquery使用animate滚动滚动条到顶部或者任意一个
位置,滚动条就好像被锁定一样,动也动不了,用过stop(),没有效果,求解,下面是代码!
<html>
<head>
<meta charset="utf-8">
<script src="j.js"></script>
<style>
* {
padding:0;
margin:0;
border:0;
}
.one,.two,.three {
display:block;
}
.one {
width:1px;
height:1px;
background-color:#f00;
}
.tow {
background-color:#00f;
}
.three {
background-color:#cecece;
}
</style>
</head>
<body>
<!-- jquery自写滚动屏幕 -->
<div class="one">one</div>
<div class="two">two</div>
<div class="three"></div>
<script>
$(document).ready(function(){
//获取当前文档的宽 高
nowWidth = $(window).width();
nowHeight = $(window).height();
//获取大的背景div
one = $(".one");
two = $(".two");
three = $(".three");
<!-- alert(typeof(nowHeight)); -->
//开始设置宽度高度为当前屏幕高度
one.css({"height":nowHeight,"width":nowWidth});
two.css({"height":nowHeight,"width":nowWidth});
three.css({"height":nowHeight,"width":nowWidth});
//开始监听滚动栏
//准备获取文档
var ht = $("document,html,body");
$(document).scroll(function(){
//获取当前滚动条距离文档高度
var top = $(document).scrollTop();
//如果高度 > 1 移动到第二屏 针对第一屏
if(top > 2 && top < nowHeight){
//设置滚动条高度为第一屏高度
ht.animate({"scrollTop":nowHeight},1000,function(){
stop(true,true);
});
}
if(top > nowHeight + 2 && top < (nowHeight * 2)){
ht.animate({"scrollTop":nowHeight *2},1000);
}
})
})
</script>
</body>
</html>
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 仅当滚动条位于顶部时,模态弹出窗口才会显示在中心
- html
- javascript
- php
- jquery
- css
- 2个回答
- vue div滚动条位置设置失败 , 这个滚动条每次都是上次的位置,我想每次都到最顶部
- html5
- css
- javascript
- vue.js
- 1个回答
- 在laravel中提交表单后,请记住滚动条位置
- javascript
- cookies
- laravel
- php
- 2个回答
- 数据刷新时,滚动条的问题
- ext
- javascript
- 0个回答
- 使用 javascript / jquery 滚动到页面顶部?
- scroll
- javascript
- jquery
- 0个回答
换一换