dixonandmoe / rellax

Lightweight, vanilla javascript parallax library
https://dixonandmoe.com/rellax/
MIT License
7.04k stars 880 forks source link

changing scrolling direction #208

Open sgarbidonna opened 4 years ago

sgarbidonna commented 4 years ago

Hi, im trying to change the direction of the scrolling while (obviusly) scrolling. I mean to scrolling on Y axis, and then on X axis. I'm not having success on this , is it possible to do what I'm looking for?

Thanks !

gingerchew commented 4 years ago

If this is the option you are looking at changing, here is how I would go about it

// this is has some pseudo/untested code, so take it with a grain of salt :)
var rellax = new Rellax('.rellax', {
    callback: function(position) {
        if (position !== value_I_Want) return;
        var newOptions = {
            vertical: false,
            horizontal: true,
            // other options you might want to change
        }
        Object.assign(rellax.options, newOptions);
        rellax.refresh();
    }
});

The gist of this is: On position update -> check if the position is what I want if not, escape else shallow merge my newOptions with the rellax.options using Object.assign then refresh the Rellax instance

I don't think this solution will work for you, due to how refresh() works. It looks like it restarts it completely, placing it back at its starting value and recalculating with the new options. You might be able to find a way around this, maybe setting a --custom-property link on the element equal to the transform3d() value before you run rellax.refresh(). Hope this at least gives you a starting point!