“JS Animate przewijaj na górę strony” Kod odpowiedzi

JS Animate przewijaj na górę strony

// Experimental: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView#Browser_compatibility
document.body.scrollIntoView({behavior: 'smooth', block: 'start'});
P. Tune

JS Animate przewijaj na górę strony

function scrollTo(element, to, duration) {
    if (duration <= 0) return;
    var difference = to - element.scrollTop;
    var perTick = difference / duration * 10;

    setTimeout(function() {
        element.scrollTop = element.scrollTop + perTick;
        if (element.scrollTop === to) return;
        scrollTo(element, to, duration - 10);
    }, 10);
}
P. Tune

Odpowiedzi podobne do “JS Animate przewijaj na górę strony”

Pytania podobne do “JS Animate przewijaj na górę strony”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu