lukehaas / Scrollify

A jQuery plugin that assists scrolling and snaps to sections.
MIT License
1.8k stars 580 forks source link

How do I scroll to the top with resetting Scrollify? #411

Closed MadstonMagic closed 3 years ago

MadstonMagic commented 3 years ago

Hi there, so I've been troubleshooting for a few days now and I can't seem to get something to work. I have a simple index.html that has a table with different rows and a single column in every row. The rows have images and I've made it so that with scrollify you snap to the next rows.

At the bottom I have a little button that when you click it, you get sent back to the top. But then when you try to scroll again it goes to the last section (or in this case the last ) you have been.

This is the code I have:

$(document).ready(function() {

$.scrollify({
    easing: "easeOutExpo",
    scrollSpeed: 1000,
    offset : 0,
    scrollbars: false,
    setHeights: false,
    overflowScroll: true,
    updateHash: false,
    touchScroll: false
});

$(function() {
    $.scrollify( {
        section : ".section",
    });
});

$(".toTop").click(function() {

    $('.blackScreen').fadeIn(1000);
    $('.blackScreen').fadeOut(1000);

    function scrollToTop() {            
        document.getElementById("home").scrollIntoView();
    }
    setTimeout(scrollToTop, 1000);
});

})

It'd be cool if someone can help me out here, I've tried using $.scrollify.disable(); and enable(); already but I probably didn't add them correctly.. Thanks in advance!

(Edit, Github is ruining the code markup. I can't get it right sorry!)

lukehaas commented 3 years ago

The issue here is your scrollToTop function. Use scrollify's move method instead.

MadstonMagic commented 3 years ago

The issue here is your scrollToTop function. Use scrollify's move method instead.

So you mean $.scrollify.move("#home");??

I have tried so but it sadly did not work, I can try again though. but last time I tried it stood in place without throwing an error.

lukehaas commented 3 years ago

Take a look at the pagination example: https://projects.lukehaas.me/scrollify/examples/pagination

MadstonMagic commented 3 years ago

I can't get it to work, I'll upload it to GitHub so you can take a look at the site itself and what I want to happen. (The button to go back to the top is at the bottom, so you'll have to scroll down first or add #end to the adress)

https://madstonmagic.github.io/wtf-creativity/

MadstonMagic commented 3 years ago

Hi Luke, I got it to work! Thanks for helping out.