Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to create the effect that you wanted in a fiddle:</p> <p><a href="http://jsfiddle.net/t0nyh0/8QTYt/36/" rel="noreferrer">http://jsfiddle.net/t0nyh0/8QTYt/36/</a></p> <p><strong>Important Tidbits</strong></p> <ol> <li>A "fixed" full-width and full-height wrapper that holds all your moving elements help you animate the div more consistently based on the scroll position (which is effectively the "keyframe" number).</li> <li><code>scroll_max</code>, <code>wrapper_width</code>, and <code>wrapper_height</code> helps normalize the dimensions of wrapper. I.e. the very bottom of the scroll corresponds to the bottom/right of the wrapper, and the very top of the scroll corresponds with the top/left of the wrapper.</li> <li>Set your body's height to whatever number of "keyframes" that you want.</li> <li>To move from top left to bottom right on going down, adjust the <code>top</code> and <code>left</code> properties. For the reverse, adjust the <code>bottom</code> and <code>right</code> properties. Of course, you will need to formulate your own calculations for more complex animations, but know that doing <code>$window.scrollTop()</code> will give you the "keyframe" number.</li> </ol> <p><strong>HTML</strong></p> <pre><code>&lt;div id="wrapper"&gt; &lt;div id="a"&gt; &lt;h1&gt;Meats&lt;/h1&gt; &lt;/div&gt; &lt;div id="b"&gt; &lt;h1&gt;Veggies&lt;/h1&gt; &lt;hr/&gt; &lt;p&gt;Veggies sunt bona vobis, proinde vos postulo esse magis daikon epazote peanut chickpea bamboo shoot rutabaga maize radish broccoli rabe lotus root kohlrabi napa cabbage courgette mustard squash mung bean.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt;​ </code></pre> <p><strong>CSS</strong></p> <pre><code>body { height: 1000px; // 1000 keyframes } #wrapper { width: 100%; height: 100%; position: fixed; border: 2px solid navy; overflow:hidden; } #a { position:absolute; background-color: #daf1d7; width: 300px; height: 300px; } #b { position: absolute; background-color: #d2d0ee; width: 200px; height: 200px; bottom: 0px; right: 0px; } </code></pre> <p>​</p> <p><strong>Javscript</strong></p> <pre><code>var $window = $(window); var $a = $('#a'); var $b = $('#b'); var scroll_max = document.documentElement.scrollHeight - document.documentElement.clientHeight; var wrapper_height = $('#wrapper').height(); var wrapper_width = $('#wrapper').width(); $window.scroll(function() { console.log(scroll_max); $a.css({ 'top': ($window.scrollTop() / scroll_max) * wrapper_height, 'left': ($window.scrollTop() / scroll_max) * wrapper_width }); $b.css({ 'bottom': ($window.scrollTop() / scroll_max) * wrapper_height, 'right': ($window.scrollTop() / scroll_max) * wrapper_width }); });​ </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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