How to make a horizontal parallax website?

Parallax, Javascript, and Read Mores

  • I placed some code to get Read More expansions on http://creatrixtiara.com/what-i-do-1/#techdigital, and it's conflicting with the parallax layout. It seems to work on Firefox, mobile, and when you change the window size, but on a fullscreen desktop it doesn't work so well. The website is hosted on SquareSpace, using the Adversary template, which allows for parallax layouts. The ideal case is http://creatrixtiara.com/who-i-am/, where everything works as intended. Yet when you go to the affected page, the pictures don't all load where they're supposed to load, unless you Read More everything. Viewing the site on mobile, changing the window size, or (strangely) viewing it on Firefox for Mac works fine. It seems that the page isn't recalculating parallax sizes on fullscreen desktop for some reason. The Read More expansion was a separate snippet of code, applied to H4s in Markdown blocks. I only ever use H4s for these. Here's the snippet of code: $(document).ready(function(){ $('.markdown-block .sqs-block-content h4').css('cursor','pointer'); $(".markdown-block .sqs-block-content h4").nextUntil("h4").slideToggle(); $(".markdown-block .sqs-block-content h4").click(function() {$(this).nextUntil("h4").slideToggle();}); }); I can't really change the code directly, but I can add code snippets to it, like the above. I'm squinting at the source code but can't seem to figure out which piece of code manipulates the parallax effect. How do I adjust the Read More code to make them compatible with the parallax layout? I would really like both there, though I would slightly prioritize the Read Mores only because that's a lot of text otherwise.

  • Answer:

    That's not really unminified, it's just a reformatted version of the minified version. (Minification changes variable names to single characters, which makes it much harder to parse what's going on.) What's probably happening is the parallax script doesn't see the page's content because it's hidden when it "looks" for it. (I'm assuming your jQuery "ready()" handler is firing before the parallax script's "domready" handler). The parallax script has a "ready()" function that sets this up (lines 59-61 on that pastebin) that doesn't seem to be invoked in the script. Are you calling this from your own script? If so, what might work is removing that and manually initializing the parallax plugin after the "Read More" animation completes. Like this:$(".markdown-block .sqs-block-content h4").click(function() { $(this).nextUntil("h4").slideToggle(function() { window.Site.initialize(); });});Note that this could cause problems if this is content that can be re-hidden (because the parallax script will probably re-bind a bunch of handlers every time it's triggered, and this will probably cause problems), but if it's a one-time reveal action it should be ok. Actually, you should probably be using $.slideDown() instead of $.slideToggle().

divabat at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

Derp, morning brain. Using $.slideDown() won't stop the event from triggering more than once. So, you want something like this instead:$(".markdown-block .sqs-block-content h4").once("click", function() { $(this).nextUntil("h4").slideToggle(function() { window.Site.initialize(); });});

neckro23

Sorry, I didn't look too hard at the page when I posted my earlier answer. I thought there was just a single "Read more". And yes, I meant "one()"... I've been using other libraries too much. Just ignore my earlier answer, it seems I was being totally wrong. Looking again at the parallax script, it seems to monitor for page changes (using a MutationObserver) and adjust itself accordingly. So, new theory: It's not noticing the page has changed because jQuery is only changing CSS properties, not anything in the DOM. Running window.site.syncUI() in the jQuery.slideToggle handler (instead of initialize) is something else to try.

neckro23

There's nothing in that code snippet that has to do with the parallex effect specifically. Basically it looks like the parallax script does some setup on the page as soon as it's ready, then your other script is changing things around more or less at the same time, so it ends up broken. When you resize the window, that triggers event listeners in the parallax script that set things right again. It's not surprising that it plays out differently on different browsers. I'd have to see the unminified code to be able to say if there's anything simple you can do to fix the conflict, but there may not be.

ludwig_van

Ooh no I might have it. Can you add this:$(window).load(function () { Site.syncUI();});

ludwig_van

Failing that, is there another way to achieve the Read More effect without breaking the parallax code?

divabat

That...sort of worked. Now the site breaks when I press "Read more" -_-

divabat

Yeah, that's what I was looking at. That code is http://en.wikipedia.org/wiki/Minification_%28programming%29 -- I'd need the unminified code to be more helpful. I see what you mean, I didn't try clicking the links before. The two scripts just seem to break each other. I tried adding a click handler to the "Read More"s that would call the setup methods again, but that didn't seem to work entirely.

ludwig_van

I turned off parallaxing, and even with (or without) the extra code it doesn't work. http://pastebin.com/QTGcwNcj

divabat

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.