Note that there are some explanatory texts on larger screens.

plurals
  1. POParallax scrolling start at specific height
    primarykey
    data
    text
    <p>I trying to implement parallax scrolling to my website. This works almost perfect. What the problem is, is that I would like to have a parallax section almost at the bottom. When I am scrolling down, is the image that I have set as background image further above, like this: <img src="https://i.stack.imgur.com/yz8vh.png" alt="enter image description here"></p> <p>The photo should already stop at the begin of the gray section, you see bellow.</p> <p>My code:</p> <pre><code>// Can also be used with $(document).ready() / $(window).load() $(document).ready(function() { // Cache the Window object $window = $(window); $('section[data-type="background"]').each(function(){ var $bgobj = $(this); // assigning the object $(window).scroll(function() { // Scroll the background at var speed // the yPos is a negative value because we're scrolling it UP! var yPos = -($window.scrollTop() / $bgobj.data('speed')); // Put together our final background position var coords = '50% '+ yPos + 'px'; // Move the background $bgobj.css({ backgroundPosition: coords }); }); // window scroll Ends }); }); </code></pre> <p>Below the HTML markup:</p> <pre><code>&lt;section class="quote" id="quote-home" data-speed="4" data-type="background"&gt; &lt;div class="container_12"&gt; &lt;header class="grid_12 centered"&gt; &lt;h1&gt; The beginning of knowlegde &lt;br&gt; is the discovery of something &lt;br&gt; we do not understand.” &lt;/h1&gt; &lt;span class="cross-x"&gt;&lt;/span&gt; &lt;h2&gt;- Frank Herbert&lt;/h2&gt; &lt;/header&gt;&lt;!-- End header.grid_12 --&gt; &lt;div class="clear"&gt;&lt;/div&gt;&lt;!-- End div.clear --&gt; &lt;/div&gt;&lt;!-- End div.container_12 --&gt; &lt;/section&gt;&lt;!-- End section#quote --&gt; &lt;section id="twitter" class="alt"&gt; </code></pre> <p></p> <p>And the css:</p> <pre><code>#quote-home { height: 500px; margin: 0 auto; width: 100%; max-width: 100%; position: relative; background: url(../images/coffeescripthands.jpg) 50% 0 no-repeat; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload