snipt

Ctrl+h for KB shortcuts

JavaScript

Back To Top

1
2
3
4
5
6
7
$('a.top').click(function(){
    $(document.body).animate({scrollTop : 0},800);
    return false;
});

// Usage:
// <a class=”top” href=”#”>Back to top</a>
https://snipt.net/embed/a8d2f59e854ec50ea14a14cf140ade20/
/raw/a8d2f59e854ec50ea14a14cf140ade20/
a8d2f59e854ec50ea14a14cf140ade20
js
JavaScript
7
2019-08-22T01:03:22
True
False
False
/api/public/snipt/109796/
back-to-top-1
<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></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="s1">&#39;a.top&#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><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">.</span><span class="nx">body</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="mi">0</span><span class="p">},</span><span class="mi">800</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">return</span> <span class="kc">false</span><span class="p">;</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><span id="L-6"><a name="L-6"></a><span class="c1">// Usage:</span> </span><span id="L-7"><a name="L-7"></a><span class="c1">// &lt;a class=”top” href=”#”&gt;Back to top&lt;/a&gt;</span> </span></pre></div> </td></tr></table>
anchor, jquery, scroll, scrolltop, top

JavaScript

Javascript Anchor link navigation

window.location = window.location + "#myLocation";
https://snipt.net/embed/396975b7b7b5872e9defa291c089be83/
/raw/396975b7b7b5872e9defa291c089be83/
396975b7b7b5872e9defa291c089be83
js
JavaScript
1
2019-08-23T08:48:49
True
False
False
/api/public/snipt/49003/
javascript-anchor-link-navigation
<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="nb">window</span><span class="p">.</span><span class="nx">location</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">location</span> <span class="o">+</span> <span class="s2">&quot;#myLocation&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
anchor, javascript, navigate

JavaScript

jQuery Smooth Scroll - scrolling anchor

1
2
3
4
5
6
7
8
/* Smooth Scroll */
    $('.totop').click(function(event){
		event.preventDefault();
		var target = this.hash;
		$('html, body').stop().animate({
			scrollTop: $(target).offset().top
		}, 500);
	});
https://snipt.net/embed/6979bb439fad0e54ef3bb25eb29784e1/
/raw/6979bb439fad0e54ef3bb25eb29784e1/
6979bb439fad0e54ef3bb25eb29784e1
js
JavaScript
8
2019-08-23T08:49:06
True
False
False
/api/public/snipt/41637/
jquery-smooth-scroll-scrolling-anchor
<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="cm">/* Smooth Scroll */</span> </span><span id="L-2"><a name="L-2"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.totop&#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="nx">event</span><span class="p">){</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">event</span><span class="p">.</span><span class="nx">preventDefault</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> <span class="kd">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">hash</span><span class="p">;</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;html, body&#39;</span><span class="p">).</span><span class="nx">stop</span><span class="p">().</span><span class="nx">animate</span><span class="p">({</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">scrollTop</span><span class="o">:</span> <span class="nx">$</span><span class="p">(</span><span class="nx">target</span><span class="p">).</span><span class="nx">offset</span><span class="p">().</span><span class="nx">top</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">},</span> <span class="mi">500</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>
anchor, jquery, scroll

PHP

Create hyperlinks within text

1
2
3
4
function create_hyperlinks_within_text( $text )
{
    return preg_replace('@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@', '<a href="http$2://$4">$1$2$3$4</a>', $text );
}
https://snipt.net/embed/fb1ba49b2d5b01df81043606cf52617a/
/raw/fb1ba49b2d5b01df81043606cf52617a/
fb1ba49b2d5b01df81043606cf52617a
php
PHP
4
2019-08-19T22:53:54
True
False
False
/api/public/snipt/39935/
create-hyperlinks-within-text
<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="x">function create_hyperlinks_within_text( $text )</span> </span><span id="L-2"><a name="L-2"></a><span class="x">{</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> return preg_replace(&#39;@(http)?(s)?(://)?(([-\w]+\.)+([^\s]+)+[^,.\s])@&#39;, &#39;&lt;a href=&quot;http$2://$4&quot;&gt;$1$2$3$4&lt;/a&gt;&#39;, $text );</span> </span><span id="L-4"><a name="L-4"></a><span class="x">}</span> </span></pre></div> </td></tr></table>
anchor, regexp, tag, text