求助:如何让页面一打开就可以自己向下滚动(内详)

baggiointer 2013-08-08 03:37:47
1.有一个很长的页面,需要一打开这个页面就自动向下滚动

2.在滚动过程中,用户点击滚动条或其他地方,滚动事件能够马上停止。我的导航条是始终悬浮在屏幕顶部的,锚链接都是链接的这一个页面的不同地方,所以我希望在页面滚动过程中,点击导航链接能跳转过去,或者用户不喜欢页面自己滚动可以自己拖动滚动条去自己想看的地方。我网上找的页面自动滚动的效果,在滚动到页面底部之前,都没办法停下来或点击链接

3.如果可以的话,希望可以在第一次滚动到页面底部之后,能够自动跳转到页面顶部,并不在滚动了(除非刷新),这一条不是很重要,能做到最好,实现不了也没关系


另外还有个小问题,这论坛积分有没有好的办法获得啊?比如购买什么的,我平时比较忙,所以不大经常来论坛赚积分
...全文
694 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
w1016910519 2014-10-21
  • 打赏
  • 举报
回复
原来如此!------------------------ 回帖就是十积分啊!
baggiointer 2013-08-09
  • 打赏
  • 举报
回复
引用 9 楼 showbo 的回复:
忘记xhtml了,改成下面的就行了,back或者css1都可以了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<div style="height:1000px"></div>
<script>
    var timer, scrollHeight, viewHeight, step = 20, sTop = 0,isScrict=document.compatMode=='CSS1Compat';
    document.onclick = function () { clearInterval(timer); }
    function Move() {
        //设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
        var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        if (nowScrollTop < sTop || (nowScrollTop - top > step)) clearInterval(timer);
        sTop += step;
        document.documentElement.scrollTop = document.body.scrollTop = sTop;
        if (sTop + viewHeight > scrollHeight) {//滚动到底部
            clearInterval(timer);
            document.documentElement.scrollTop = document.body.scrollTop = 0//跳转到顶部
        }
    }
    window.onresize = function () {
        viewHeight = document[isScrict?'documentElement':'body'].clientHeight;
        scrollHeight = document[isScrict?'documentElement':'body'].scrollHeight;
    }
    window.onload = function () {
        window.onresize();
        timer = setInterval(Move, 100);
    }
</script>
非常感谢,都符合我的要求了,不过我加了一段控制导航浮动的js之后,页面在滚动到最底部之后不会自动返回顶部了,应该是这两段js略有冲突吧? function tools(){ var top=$(document).scrollTop(); if(($.browser.msie==true)&&($.browser.version==6.0)){ if(top>168)$("#box1_1").css({position:"absolute",top:top-168}); }else{ if(top>168)$("#box1_1").css({position:"fixed",top:0}); } if(top<=168)$("#box1_1").css({position:"static",top:0}); } $(function(){ window.onscroll=tools; window.onresize=tools; }); </script>
  • 打赏
  • 举报
回复
忘记xhtml了,改成下面的就行了,back或者css1都可以了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<div style="height:1000px"></div>
<script>
    var timer, scrollHeight, viewHeight, step = 20, sTop = 0,isScrict=document.compatMode=='CSS1Compat';
    document.onclick = function () { clearInterval(timer); }
    function Move() {
        //设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
        var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        if (nowScrollTop < sTop || (nowScrollTop - top > step)) clearInterval(timer);
        sTop += step;
        document.documentElement.scrollTop = document.body.scrollTop = sTop;
        if (sTop + viewHeight > scrollHeight) {//滚动到底部
            clearInterval(timer);
            document.documentElement.scrollTop = document.body.scrollTop = 0//跳转到顶部
        }
    }
    window.onresize = function () {
        viewHeight = document[isScrict?'documentElement':'body'].clientHeight;
        scrollHeight = document[isScrict?'documentElement':'body'].scrollHeight;
    }
    window.onload = function () {
        window.onresize();
        timer = setInterval(Move, 100);
    }
</script>
baggiointer 2013-08-09
  • 打赏
  • 举报
回复
引用 7 楼 showbo 的回复:
firefox12,ie7,8,chrome都没有问题,测试过的,你什么浏览器
哦哦,我知道了,你的这段代码如果加上 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> 就不起作用了,能不能让他符合这个标准啊?
  • 打赏
  • 举报
回复
firefox12,ie7,8,chrome都没有问题,测试过的,你什么浏览器
baggiointer 2013-08-09
  • 打赏
  • 举报
回复
引用 3 楼 showbo 的回复:
<div style="height:1000px"></div>
<script>
    var timer, scrollHeight, viewHeight, step = 20, sTop = 0;
    document.onclick = function () { clearInterval(timer); }
    function Move() {
        //设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
        var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
        if (nowScrollTop < sTop || (nowScrollTop - top > step)) clearInterval(timer);
        sTop += step;
        document.documentElement.scrollTop = document.body.scrollTop = sTop;
        if (sTop + viewHeight > scrollHeight) {//滚动到底部
            clearInterval(timer);
            document.documentElement.scrollTop = document.body.scrollTop = 0//跳转到顶部
        }
    }
    window.onresize = function () {
        viewHeight = document.body.clientHeight;
        scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
    }
    window.onload = function () {
        window.onresize();
        timer = setInterval(Move, 100);
    }
</script>
呃,你的这段代码没作用啊
  • 打赏
  • 举报
回复
不要覆盖原来的onresize,改成这样,因为在onload中调用 window.onscroll获取视窗和滚动高作为是否滚动到页脚的代码
//window.onscroll=tools;
//window.onresize=tools;
//===>
$(window).bind({scroll:tools,resize:tools})
为了那份宁静 2013-08-08
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
至于论坛积分,你可以联系下管理员看看,换点¥让他们给你充值别。。
  • 打赏
  • 举报
回复
<div style="height:1000px"></div>
<script>
var timer, scrollHeight, viewHeight, step = 20, sTop = 0;
document.onclick = function () { clearInterval(timer); }
function Move() {
//设置滚动前获取当前的的滚动高度和sTop比较,如果小于sTop或者和sTop的差距大于step定义的,说明拖拽过滚动条了
var nowScrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
if (nowScrollTop < sTop || (nowScrollTop - top > step)) clearInterval(timer);
sTop += step;
document.documentElement.scrollTop = document.body.scrollTop = sTop;
if (sTop + viewHeight > scrollHeight) {//滚动到底部
clearInterval(timer);
document.documentElement.scrollTop = document.body.scrollTop = 0//跳转到顶部
}
}
window.onresize = function () {
viewHeight = document.body.clientHeight;
scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
}
window.onload = function () {
window.onresize();
timer = setInterval(Move, 100);
}
</script>
baggiointer 2013-08-08
  • 打赏
  • 举报
回复
引用 1 楼 showbo 的回复:
每天回个帖就有10分了
时间上没那么充足....
  • 打赏
  • 举报
回复
每天回个帖就有10分了

87,995

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧