Sha256: 0d591ea3041c66f5fc35052cb7a6ede6df6dadf29817006f2d59ffab5e31678c

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

<div class="">
    <a href="#" id="back-to-top">
        &#10148;
    </a>
</div>

<script type="text/javascript">
    function scrollToTop() {
        let cosParameter = window.scrollY / 2,
            scrollCount = 0,
            scrollDuration = 500,
            oldTimestamp = performance.now();
        function step(newTimestamp) {
            scrollCount += Math.PI / (scrollDuration / newTimestamp - oldTimestamp);
            if (scrollCount >= Math.PI) window.scrollTo(0, 0);
            if (window.scrollY === 0) return;
            window.scrollTo(0, Math.round(cosParameter + cosParameter * Math.cos(scrollCount)));
            oldTimestamp = newTimestamp;
            window.requestAnimationFrame(step);
            console.log('step...');
        }
        window.requestAnimationFrame(step);
        document.getElementById('back-to-top').style.display = 'none';
    }

    document.getElementById('back-to-top').click(scrollToTop);

    document.onscroll = function() {
        if (window.scrollY >= 500) {
            document.getElementById('back-to-top').style.display = 'block';
        } else {
            document.getElementById('back-to-top').style.display = 'none';
        }
    }


</script>

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jekyll-theme-ink-0.1.3 _includes/back-to-top.html
jekyll-theme-ink-0.1.2 _includes/back-to-top.html
jekyll-theme-ink-0.1.1 _includes/back-to-top.html
jekyll-theme-ink-0.1.0 _includes/back-to-top.html