snipt

Ctrl+h for KB shortcuts

JavaScript

Make item scroll slower than window (Parallax)

1
2
3
4
5
$(window).scroll(function () { 
   $('#object').css({
      'bottom' : -($(this).scrollTop()/10)+"px" // increase # to make even slower
   }); 
});
https://snipt.net/embed/722d16388068ce3814f91cdae688b479/
/raw/722d16388068ce3814f91cdae688b479/
722d16388068ce3814f91cdae688b479
js
JavaScript
5
2019-07-16T19:25:45
True
False
False
/api/public/snipt/59214/
make-item-scroll-slower-than-window-parallax
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="nb">window</span><span class="p">).</span><span class="nx">scroll</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#object&#39;</span><span class="p">).</span><span class="nx">css</span><span class="p">({</span> </span><span id="L-3"><a name="L-3"></a> <span class="s1">&#39;bottom&#39;</span> <span class="o">:</span> <span class="o">-</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">scrollTop</span><span class="p">()</span><span class="o">/</span><span class="mi">10</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;px&quot;</span> <span class="c1">// increase # to make even slower</span> </span><span id="L-4"><a name="L-4"></a> <span class="p">});</span> </span><span id="L-5"><a name="L-5"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
javascript, jquery, parallax

JavaScript

Parallax - Scale based on distance to camera

1
2
3
4
cam = thisComp.layer("Camera 1");
dist = length(position[2] - cam.position[2]);
s = dist/cam.zoom;
scale*s;
https://snipt.net/embed/11b81dd2f2b533a144f54802e3519ed7/
/raw/11b81dd2f2b533a144f54802e3519ed7/
11b81dd2f2b533a144f54802e3519ed7
js
JavaScript
4
2019-07-06T05:42:10
True
False
False
Sep 11, 2013 at 01:05 AM
/api/public/snipt/55869/
parallax-scale-based-on-distance-to-camera
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">cam</span> <span class="o">=</span> <span class="nx">thisComp</span><span class="p">.</span><span class="nx">layer</span><span class="p">(</span><span class="s2">&quot;Camera 1&quot;</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">dist</span> <span class="o">=</span> <span class="nx">length</span><span class="p">(</span><span class="nx">position</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">-</span> <span class="nx">cam</span><span class="p">.</span><span class="nx">position</span><span class="p">[</span><span class="mi">2</span><span class="p">]);</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">s</span> <span class="o">=</span> <span class="nx">dist</span><span class="o">/</span><span class="nx">cam</span><span class="p">.</span><span class="nx">zoom</span><span class="p">;</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">scale</span><span class="o">*</span><span class="nx">s</span><span class="p">;</span> </span></pre></div> </td></tr></table>
ae, expressions, parallax