Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running multiple scenes at once #103

Closed
farhoudz opened this issue Oct 23, 2014 · 5 comments
Closed

Running multiple scenes at once #103

farhoudz opened this issue Oct 23, 2014 · 5 comments

Comments

@farhoudz
Copy link

I have a one-page web project containing four sections and so far using your amazing library I have written this code before the closing body tag :

var firstScene = document.getElementById('first-scene');
var firstParallax = new Parallax(firstScene);

var secondScene = document.getElementById('second-scene');
var secondParallax = new Parallax(secondScene);

var thirdScene = document.getElementById('third-scene');
var thirdParallax = new Parallax(thirdScene);

var fourthScene = document.getElementById('fourth-scene');
var fourthParallax = new Parallax(fourthScene);

My question is that is it possible to call all for scenes in one new parallax ? also when I put this code in an external js file it does not run at all, why?

Thanks in advance

@sidonaldson
Copy link

@farhoudz did you get anywhere with this? I'm considering this solution too. It won't work with relative bounds but if the CSS is set up right and parallax is invoked on a parent element it should work

@Gil-Goldshlager
Copy link

You need to create an array, and then loop all scenes:

Set an array and select all the scenes as:

var scenes = [];
var scenesSelector = document.querySelectorAll('.scene');

Then run a loop:

for(i=0; i<scenesSelector.length; i++){
    scenes[i] = new Parallax(scenesSelector[i]);
}

Later if and you want to be able to disable/enable all of them together then create a function for that as:

function scenesDisable(){
    for(i=0; i<scenes.length; i++){
        scenes[i].disable();
    }
}

function scenesEnable(){
    for(i=0; i<scenes.length; i++){
        scenes[i].enable();
    }
}

@vivekkupadhyay
Copy link

@Gil-Goldshlager thanks a lot, it really worked for me. 💯

@satiroglumustafa
Copy link

Thanks a lot, I used swiper slide and doesnt work for every slide item parallax.js, but this solution worked for me

@santiagosj
Copy link

I`m wondering how to get multiple scenes but in reactjs..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants