简体   繁体   中英

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.

<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.

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

This one worked for me.

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

Use CSS

.divClass{
    overflow:scroll;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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