简体   繁体   English

如何一直向下滚动我动态生成的 HTML 页面并从顶部再次开始滚动?

[英]How to scroll my dynamically generated HTML Page all the way down and start scrolling again from the top?

I have a HTML page that is just simple html page with an empty table tag.我有一个 HTML 页面,它只是一个带有空 table 标签的简单 html 页面。

This table is filled using a javascript function.该表是使用 javascript 函数填充的。 I basically read a file and fill rows from the data of the file.我基本上读取一个文件并从文件的数据中填充行。 This part I have implemented properly.这部分我已经正确实施了。

I have 100 table rows.我有 100 个表行。 I would like to scroll my HTML Page all the way down and then once it has finished scrolling starting to reverse the scroll back to top again.我想一直向下滚动我的 HTML 页面,然后一旦它完成滚动,就开始再次将滚动返回到顶部。

I have found an example online: https://jsfiddle.net/maherhossain/a24nymv1/ .我在网上找到了一个例子: https : //jsfiddle.net/maherhossain/a24nymv1/ However, this only works horizontally.但是,这只适用于水平。 I have tried to do this vertically and have submitted the code below.我尝试垂直执行此操作并提交了下面的代码。

I am not getting any errors.我没有收到任何错误。 The table is being loaded.正在加载表。 Its just that the automatic scrolling is not working.只是自动滚动不起作用。

I would appreciate any help.我将不胜感激任何帮助。 Many Thanks in advance.提前谢谢了。

HTML: HTML:

<div id="scroll">
    <body onload="loadXMLDoc()">
<table class="content-table" id="demo"></table>
/div>

CSS: CSS:

#scroll { white-space: nowrap; overflow-y: scroll; }

Javascript: Javascript:

<script>
// {} ...Function to load the file in table

function animatethis(targetElement, speed) {
    var scrollHeight = $(targetElement).get(0).scrollHeight;
    var clientHeight = $(targetElement).get(0).clientHeight;
    $(targetElement).animate({ scrollTop: scrollHeight - clientHeight },
    {
        duration: speed,
        complete: function () {
            targetElement.animate({ scrollTop: 0 },
            {
                duration: speed,
                complete: function () {
                    animatethis(targetElement, speed);
                }
            });
        }
    });
};
animatethis($('#scroll'), 5000);

scrollDown isn't an animation. scrollDown 不是动画。 Try scrollTop.尝试滚动顶部。 You may have to rethink the math behind it though.不过,您可能需要重新考虑其背后的数学原理。

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

相关问题 如何一直向下滚动 HTML 页面并从顶部重新启动? - How to scroll HTML Page all the way down and restart again from top? 动态生成的页面向下滚动 - Dynamically generated page scrolling down 完美滚动到顶部。 但是当我向下滚动并单击页面上的任意位置时,滚动再次移至顶部 - Perfectly scroll to top. but when i scroll down and click anywhere on page, again scroll moves to the top 当我从顶部滚动时如何暂停转盘/滑块,然后再滚动至顶部时又重新开始? - How can I pause carousel/slider when I scroll from top and start again when I scroll to top? 如何使滚动条从每个页面的顶部开始 - How to make scroll bar start from the top in every page 如何滚动到每个选项列表并返回顶部重新开始 - How to scroll to each option list and back to the top to start again 如何通过向下滚动页面来向下滚动元素? - How to move elements on scroll-down with scrolling down the page? 滚动下来时,有没有办法在我的网站上创建一个div? - Is there a way to make a div on my website that follows on top when scrolling down? JavaScript-“向下滚动”按钮-从着陆页滚动到标题顶部 - JavaScript - “Scroll Down” Button - Scroll From Landing Page to Top of the Header 如何在向下滚动时动态偏移顶部条形高度 - How to offset top bar height dynamically when scrolling down
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM