snipt

Ctrl+h for KB shortcuts

JavaScript

jQuery - Animated page scrolling

1
2
3
4
5
6
7
8
//Add .scrollPage class to any element you want to have a scrolling action

$('.scrollPage').click(function() {
    	var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
	return false;
	});
https://snipt.net/embed/291992d90d122ff14fbb323eebe6df3f/
/raw/291992d90d122ff14fbb323eebe6df3f/
291992d90d122ff14fbb323eebe6df3f
js
JavaScript
8
2019-08-21T07:43:10
True
False
False
/api/public/snipt/41178/
animated-page-scrolling
<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> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//Add .scrollPage class to any element you want to have a scrolling action</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.scrollPage&#39;</span><span class="p">).</span><span class="nx">click</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">elementClicked</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s2">&quot;href&quot;</span><span class="p">);</span> </span><span id="L-5"><a name="L-5"></a> <span class="kd">var</span> <span class="nx">destination</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="nx">elementClicked</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span><span class="p">;</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;html:not(:animated),body:not(:animated)&quot;</span><span class="p">).</span><span class="nx">animate</span><span class="p">({</span> <span class="nx">scrollTop</span><span class="o">:</span> <span class="nx">destination</span><span class="o">-</span><span class="mi">20</span><span class="p">},</span> <span class="mi">500</span> <span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="kc">false</span><span class="p">;</span> </span><span id="L-8"><a name="L-8"></a> <span class="p">});</span> </span></pre></div> </td></tr></table>
animated, animation, scroll

HTML

Embed Nerd

<a href="http://www.bassnectar.net" target="_blank"><img src="http://bassnectar.net/home/wp-content/uploads/releasethenerd.gif" border="0" alt="Get Bassnectar"></a>
https://snipt.net/embed/e492b530eb3d7cd90b077844ba1c7411/
/raw/e492b530eb3d7cd90b077844ba1c7411/
e492b530eb3d7cd90b077844ba1c7411
html
HTML
1
2019-08-20T03:49:26
True
False
False
/api/public/snipt/5089/
get-nerd
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;http://www.bassnectar.net&quot;</span> <span class="na">target</span><span class="o">=</span><span class="s">&quot;_blank&quot;</span><span class="p">&gt;&lt;</span><span class="nt">img</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;http://bassnectar.net/home/wp-content/uploads/releasethenerd.gif&quot;</span> <span class="na">border</span><span class="o">=</span><span class="s">&quot;0&quot;</span> <span class="na">alt</span><span class="o">=</span><span class="s">&quot;Get Bassnectar&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
animated, gif