I have a code that on button press runs autoscroll on a single table and when I use the autoscroll speed of 2500, the autoscroll works as it should to the end of the table, but when I change the speed to let’s say 11500 autoscroll works but not to the end of the table, 70% of the board just does autoscroll, so what should I need to change in the code to fix this error?
The same code and same table but I need an option to Scroll Page from Top to Bottom, then Back Up (and Repeat), please check the code of my autoscroll option and what should I change or insert to enable this option?
ini_set('MAX_EXECUTION_TIME', -1);
define('SRT_STATE_SUBNUMBER', 0);
define('SRT_STATE_TIME', 1);
define('SRT_STATE_TEXT', 2);
define('SRT_STATE_BLANK', 3);
$lines = file("uploads/".$file_name);
$subs = array();
$state = SRT_STATE_SUBNUMBER;
$subNum = 0;
$subText = '';
$subTime = '';
foreach($lines as $line) {
switch($state) {
case SRT_STATE_SUBNUMBER:
$subNum = trim($line);
$state = SRT_STATE_TIME;
break;
case SRT_STATE_TIME:
$subTime = trim($line);
$state = SRT_STATE_TEXT;
break;
case SRT_STATE_TEXT:
if (trim($line) == '') {
$sub = new stdClass;
$sub->number = $subNum;
list($sub->startTime, $sub->stopTime) = explode(' --> ', $subTime);
$sub->text = $subText;
$subText = '';
$state = SRT_STATE_SUBNUMBER;
$subs[] = $sub;
} else {
$subText .= $line;
}
break;
}
}
if ($state == SRT_STATE_TEXT) {
// if file was missing the trailing newlines, we'll be in this
// state here. Append the last read text and add the last sub.
$sub->text = $subText;
$subs[] = $sub;
}
?>
document.getElementById('table').style.display = 'block';
}
function autoScroll(){
window.scrollBy(0,400)
var objDiv = document.getElementById("table");
smooth_scroll_to(objDiv, objDiv.scrollHeight, 15900);
}
var smooth_scroll_to = function(element, target, duration) {
target = Math.round(target);
duration = Math.round(duration);
if (duration < 0) {
return Promise.reject("bad duration");
}
if (duration === 0) {
element.scrollTop = target;
return Promise.resolve();
}
var start_time = Date.now();
var end_time = start_time + duration;
var start_top = element.scrollTop;
var distance = target - start_top;
var smooth_step = function(start, end, point) {
if(point <= start) { return 0; }
if(point >= end) { return 1; }
var x = (point - start) / (end - start);
return x*x*(3 - 2*x);
}
return new Promise(function(resolve, reject) {
var previous_top = element.scrollTop;
var scroll_frame = function() {
if(element.scrollTop != previous_top) {
reject("interrupted");
return;
}
var now = Date.now();
var point = smooth_step(start_time, end_time, now);
var frameTop = Math.round(start_top + (distance * point));
element.scrollTop = frameTop;
if(now >= end_time) {
resolve();
return;
}
if(element.scrollTop === previous_top
&& element.scrollTop !== frameTop) {
resolve();
return;
}
previous_top = element.scrollTop;
setTimeout(scroll_frame, 0); } setTimeout(scroll_frame, 0); }); }