[英]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.