/    Sign up×
Community /Pin to ProfileBookmark

Scroll from top to Bottom, then Back Up!

  • 1.

    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?

  • 2.

    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); }); }
    `

    to post a comment
    CSSHTMLJavaScript

    0Be the first to comment 😎

    ×

    Success!

    Help @macano113 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.6,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...