Skip to content

Container Margins / Centering #1

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

Open
bryannielsen opened this issue Aug 8, 2011 · 2 comments
Open

Container Margins / Centering #1

bryannielsen opened this issue Aug 8, 2011 · 2 comments

Comments

@bryannielsen
Copy link

There's an issue with wrapping the whole ul element in index.html with say a <div style="width: 960px; margin: 0 auto;">, the images all jerk to the right on the first scroll.

I haven't had a chance to div into the script and see where the problem is, but if that sounds like something that might be a quick fix, I'd love to use the script, just need to center the content :-)

Great script, thanks for your work!

@bredon
Copy link

bredon commented Oct 2, 2011

I had a similar problem - the background images would always jump 50px to the right on the first scroll and then stay there. Since I only need y-axis scrolling and I needed the background to always be centered, I simply updated line #130 from this:
$this.css({'backgroundPosition': parseInt(newXPos) + "px " + parseInt(newYPos) +"px"});
to this:
$this.css({'backgroundPosition': "50%" + parseInt(newYPos) +"px"});

I couldn't ever figure out where that 50px was coming from, but this solved my problem so I'm happy.

@smisaacs
Copy link

smisaacs commented Nov 7, 2011

The 50 comes from lines 107 and 123.

107 says grab the 1st part of the position array and strip out non-numerical characters. So if you had '50%' in there to center your item, then you have '50' left after the replace. In line 123, its saying if we aren't parallaxing the x-axis, use the value we have after the replace, which by default the browser makes into 50px. If you want to keep your x position intact, you can change line 135 to
$this.css({'backgroundPosition': currentPosArray[0] + parseInt(newYPos) +"px"});

Now this wont keep your child items inside a container, you'd have to do some extra work to check where the parent is and adjust your child based on that.

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

3 participants