Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

JavaScript

Fancybox open from needed index

$.fancybox.open($('.fancybox'), {index: 0});
https://snipt.net/embed/4d744b9fa5a28fda34ebe36ec7df5f47/
https://snipt.net/raw/4d744b9fa5a28fda34ebe36ec7df5f47/
4d744b9fa5a28fda34ebe36ec7df5f47
js
JavaScript
1
2016-12-02T11:01:39
True
False
False
Mar 22, 2014 at 07:02 AM
/api/public/snipt/123027/
fancybox-open-from-needed-index
<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="nx">$</span><span class="p">.</span><span class="nx">fancybox</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;.fancybox&#39;</span><span class="p">),</span> <span class="p">{</span><span class="nx">index</span><span class="o">:</span> <span class="mi">0</span><span class="p">});</span> </span></pre></div> </td></tr></table>
box, fancy, fancybox, gallery, image, images, jquery, modal, plugin

JavaScript

Fix broken images automatically

1
2
3
$('img').error(function(){
	$(this).attr('src', img/broken.png);
});
https://snipt.net/embed/2bfa40e8fcee9dbd650cb1a9b2734eff/
https://snipt.net/raw/2bfa40e8fcee9dbd650cb1a9b2734eff/
2bfa40e8fcee9dbd650cb1a9b2734eff
js
JavaScript
3
2016-12-02T16:04:36
True
False
False
Feb 11, 2014 at 02:17 AM
/api/public/snipt/112591/
fix-broken-images-automatically-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></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;img&#39;</span><span class="p">).</span><span class="nx">error</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="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;src&#39;</span><span class="p">,</span> <span class="err">‘</span><span class="nx">img</span><span class="o">/</span><span class="nx">broken</span><span class="p">.</span><span class="nx">png</span><span class="err">’</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
images, javascript

JavaScript

Check if images are loaded

1
2
3
$('img').load(function() {
	console.log('image load successful');
});
https://snipt.net/embed/0b8599f3aa0e7180e0640d69b8ad82db/
https://snipt.net/raw/0b8599f3aa0e7180e0640d69b8ad82db/
0b8599f3aa0e7180e0640d69b8ad82db
js
JavaScript
3
2016-12-02T10:25:27
True
False
False
/api/public/snipt/109798/
check-if-images-are-loaded
<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></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;img&#39;</span><span class="p">).</span><span class="nx">load</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">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;image load successful&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
check, images, jquery, load

JavaScript

Snippet3

1
2
3
$('img').error(function(){
	$(this).attr('src', 'img/broken.png');
});
https://snipt.net/embed/21df4dad69f97e6aeba1b33dfd08406e/
https://snipt.net/raw/21df4dad69f97e6aeba1b33dfd08406e/
21df4dad69f97e6aeba1b33dfd08406e
js
JavaScript
3
2016-12-02T16:04:41
True
False
False
Jan 21, 2014 at 12:43 PM
/api/public/snipt/107560/
snippet3
<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></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;img&#39;</span><span class="p">).</span><span class="nx">error</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="k">this</span><span class="p">).</span><span class="nx">attr</span><span class="p">(</span><span class="s1">&#39;src&#39;</span><span class="p">,</span> <span class="s1">&#39;img/broken.png&#39;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
images

JavaScript

snippet2

1
2
3
$('img').load(function() {
	//se cargaron las imagenes completamente
});
https://snipt.net/embed/4b75498dcdbdaa6ffb5015242614b2c3/
https://snipt.net/raw/4b75498dcdbdaa6ffb5015242614b2c3/
4b75498dcdbdaa6ffb5015242614b2c3
js
JavaScript
3
2016-12-02T16:04:43
True
False
False
Jan 21, 2014 at 12:42 PM
/api/public/snipt/107559/
snippet2
<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></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;img&#39;</span><span class="p">).</span><span class="nx">load</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="c1">//se cargaron las imagenes completamente</span> </span><span id="L-3"><a name="L-3"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
images
Copyrighted, illegal, or inappropriate content? Email [email protected].