snipt

Ctrl+h for KB shortcuts

JavaScript

Get Viewport width. jQuery

1
2
3
4
5
6
7
8
function viewportWidth() {
    var $body = $('body'),
        viewPortWidth = $body.css('overflow', 'hidden').width();
    
    $body.css('overflow', '');

    return viewPortWidth;
}
https://snipt.net/embed/9935d9ab42e952161c3411323936eafc/
https://snipt.net/raw/9935d9ab42e952161c3411323936eafc/
9935d9ab42e952161c3411323936eafc
js
JavaScript
8
2016-09-24T13:37:43
True
False
False
Apr 05, 2014 at 03:42 PM
/api/public/snipt/127685/
get-viewport-width-jquery
<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 id="L-1"><a name="L-1"></a><span class="kd">function</span> <span class="nx">viewportWidth</span><span class="p">()</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">$body</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;body&#39;</span><span class="p">),</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">viewPortWidth</span> <span class="o">=</span> <span class="nx">$body</span><span class="p">.</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;overflow&#39;</span><span class="p">,</span> <span class="s1">&#39;hidden&#39;</span><span class="p">).</span><span class="nx">width</span><span class="p">();</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$body</span><span class="p">.</span><span class="nx">css</span><span class="p">(</span><span class="s1">&#39;overflow&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> </span><span id="L-7"><a name="L-7"></a> <span class="k">return</span> <span class="nx">viewPortWidth</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>
function, jquery, simple, width

Java

24

1
2
3
4
5
6
class Example
{
public static void main(Strings args[])
{
    System.out.println();
}
https://snipt.net/embed/221b15cb6ec1747e11f851b93cb462c1/
https://snipt.net/raw/221b15cb6ec1747e11f851b93cb462c1/
221b15cb6ec1747e11f851b93cb462c1
java
Java
7
2016-09-22T14:13:22
True
False
True
Mar 11, 2014 at 02:03 PM
/api/public/snipt/120984/
-13931
<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></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">class</span> <span class="nc">Example</span> </span><span id="L-2"><a name="L-2"></a><span class="o">{</span> </span><span id="L-3"><a name="L-3"></a><span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">Strings</span> <span class="n">args</span><span class="o">[])</span> </span><span id="L-4"><a name="L-4"></a><span class="o">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">();</span> </span><span id="L-6"><a name="L-6"></a><span class="o">}</span> </span></pre></div> </td></tr></table>
example, simple

JavaScript

Hide block on click outside of them

1
2
3
4
5
6
7
$(document).on('click', function(e) {
	var $container = $("#block");

	if (!$container.is(e.target) && $container.has(e.target).length === 0) {
		$container.hide();
	}
});
https://snipt.net/embed/0dc3ee6be83acf2f279c8f0ff1d1ba57/
https://snipt.net/raw/0dc3ee6be83acf2f279c8f0ff1d1ba57/
0dc3ee6be83acf2f279c8f0ff1d1ba57
js
JavaScript
7
2016-09-23T01:37:58
True
False
False
/api/public/snipt/120311/
hide-block-on-click-outside-of-them
<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 id="L-1"><a name="L-1"></a><span class="nx">$</span><span class="p">(</span><span class="nb">document</span><span class="p">).</span><span class="nx">on</span><span class="p">(</span><span class="s1">&#39;click&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">var</span> <span class="nx">$container</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#block&quot;</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">$container</span><span class="p">.</span><span class="nx">is</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nx">$container</span><span class="p">.</span><span class="nx">has</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">target</span><span class="p">).</span><span class="nx">length</span> <span class="o">===</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">$container</span><span class="p">.</span><span class="nx">hide</span><span class="p">();</span> </span><span id="L-6"><a name="L-6"></a> <span class="p">}</span> </span><span id="L-7"><a name="L-7"></a><span class="p">});</span> </span></pre></div> </td></tr></table>
click, hide, jquery, simple, snipet
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.