【问题标题】:scroll to bottom on page load but will allow to scroll on top在页面加载时滚动到底部,但允许在顶部滚动
【发布时间】:2015-11-29 02:54:18
【问题描述】:

我想在页面加载时将 div bottom 滚动到页面底部,但也想在需要时向上滚动以了解如何在没有任何动画的情况下将其存档如何实现 echo "<div id='bottom'><p><b>$from_username</b><br />$message</p></div>";

<script>

    function scrollpage() {     
        function f() 
        {
            window.scrollTo(0,i);
            if(status==0) {
                i=i+40;
                if(i>=Height){  status=1; } 
            } 
        setTimeout( f, 0.01 );
        }f();
    }
    var Height=document.documentElement.scrollHeight;
    var i=1,j=Height,status=0;
    scrollpage();
    </script>

这就是我目前所拥有的,我可以自动向下滚动,但是当我想向上滚动时不能向上滚动,如果我想向上滚动该怎么办?

【问题讨论】:

  • 好吧,你一直在调用它,因为你的 scrollpage();通话没有包含任何内容
  • 你是对的,所以任何关于我如何向上滚动该特定 div 的想法
  • 正在处理它。给我5分钟
  • 我们去吧。使用我的新解决方案,一切顺利。
  • 我认为现在一切正常?

标签: php jquery css


【解决方案1】:

Scroll to bottom of Div on page load (jQuery) 在这里我找到了为您整理所需的代码。

    <script>
        $( document ).ready(function() { 
            var d = $('#div1');
            d.scrollTop(d.prop("scrollHeight"));
            console.log("at the bottom!");
        });
    </script>
    </head>
    <body>
    <p>top</p>
    <div style="max-height: 200px;">
    <div id='div1' style='background-color:grey;width:200px;overflow:scroll;overflow-x:hidden;max-height:200px;'>
    <p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p></div>
    </div>
    <p>bottom</p>
    <p>text under the div</p>
    </body>
</html>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-11
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 2012-05-17
    • 1970-01-01
    相关资源
    最近更新 更多