简体   繁体   English

在DIV-Javascript中添加AutoScroll

[英]Adding AutoScroll inside a DIV-Javascript

How do I add an auto scroll function to the below file? 如何在以下文件中添加自动滚动功能?

By auto scroll I mean it automatically scrolls to the bottom within the scrollable area and then start from the top again. 自动滚动是指它自动滚动到可滚动区域的底部,然后再次从顶部开始。

I tried different JavaScript code, but none of it worked. 我尝试了其他JavaScript代码,但没有一个起作用。

<div class="box">
    <div class="box-heading"><?php echo $heading_title; ?></div>
    <div class="box-content">
        <?php foreach ($all_news as $news) { ?>
            <div align="center">
            </div>
            <div style="
                width: 98%;
                height: 200px;
                overflow-y:auto;">

                <script type="text/javascript" src="http://domain.com/file.php"></script>
                <div id="feedmain" class="feed11"><a href="http://www.domain.com">PFeed</a></div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

The file.php we are loading is only an HTML table. 我们正在加载的file.php只是一个HTML表。

您可以使用overflow-y:scroll而不是overflow-y:auto

This one worked for me. 这个为我工作。

var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;

Use CSS 使用CSS

.divClass{
    overflow:scroll;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM