snipt

Ctrl+h for KB shortcuts

JavaScript

Event Trigger When User Scrolls To Element jQuery

1
2
3
4
5
6
7
8
var target = $('p').offset().top;

var interval = setInterval(function() {
    if ($(window).scrollTop() >= target) {
        alert('here it is!');
        clearInterval(interval);
    }
}, 200);
https://snipt.net/embed/bc7fa157a67a27f709fd4ed6ba3e8d44/
https://snipt.net/raw/bc7fa157a67a27f709fd4ed6ba3e8d44/
bc7fa157a67a27f709fd4ed6ba3e8d44
js
JavaScript
8
2016-09-29T17:12:21
True
False
False
Jan 28, 2013 at 10:43 AM
/api/public/snipt/54643/
event-trigger-when-user-scrolls-to-element-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">var</span> <span class="nx">target</span> <span class="o">=</span> <span class="nx">$</span><span class="p">(</span><span class="s1">&#39;p&#39;</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-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">interval</span> <span class="o">=</span> <span class="nx">setInterval</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="k">if</span> <span class="p">(</span><span class="nx">$</span><span class="p">(</span><span class="nb">window</span><span class="p">).</span><span class="nx">scrollTop</span><span class="p">()</span> <span class="o">&gt;=</span> <span class="nx">target</span><span class="p">)</span> <span class="p">{</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">alert</span><span class="p">(</span><span class="s1">&#39;here it is!&#39;</span><span class="p">);</span> </span><span id="L-6"><a name="L-6"></a> <span class="nx">clearInterval</span><span class="p">(</span><span class="nx">interval</span><span class="p">);</span> </span><span id="L-7"><a name="L-7"></a> <span class="p">}</span> </span><span id="L-8"><a name="L-8"></a><span class="p">},</span> <span class="mi">200</span><span class="p">);</span> </span></pre></div> </td></tr></table>
event, javascript, jquery, trigger

JavaScript

jQuery Click

1
2
3
4
5
6
7
function XLS_DL_ClickListener() {
    $("a#download_xls").click(function() {
        $("#m2_MB_btnSubmit2").trigger('click');

        return false;
    });
}
https://snipt.net/embed/d9f530e9a1b9c092b306c21d6998d260/
https://snipt.net/raw/d9f530e9a1b9c092b306c21d6998d260/
d9f530e9a1b9c092b306c21d6998d260
js
JavaScript
7
2016-09-21T10:24:02
True
False
False
Jan 19, 2013 at 10:20 AM
/api/public/snipt/54025/
jquery-click
<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="kd">function</span> <span class="nx">XLS_DL_ClickListener</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="s2">&quot;a#download_xls&quot;</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-3"><a name="L-3"></a> <span class="nx">$</span><span class="p">(</span><span class="s2">&quot;#m2_MB_btnSubmit2&quot;</span><span class="p">).</span><span class="nx">trigger</span><span class="p">(</span><span class="s1">&#39;click&#39;</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="k">return</span> <span class="kc">false</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>
button, click, jquery, trigger

JavaScript

Intervalo de Tiempo

1
2
3
setInterval(
   function(){$('#right_scroll_index img').trigger("click")}, 
      6000);
https://snipt.net/embed/52c5dbefc93aba478583082f62fc6609/
https://snipt.net/raw/52c5dbefc93aba478583082f62fc6609/
52c5dbefc93aba478583082f62fc6609
js
JavaScript
4
2016-09-29T11:25:05
True
False
False
/api/public/snipt/36071/
intervalo-de-tiempo
<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 id="L-1"><a name="L-1"></a><span class="nx">setInterval</span><span class="p">(</span> </span><span id="L-2"><a name="L-2"></a> <span class="kd">function</span><span class="p">(){</span><span class="nx">$</span><span class="p">(</span><span class="s1">&#39;#right_scroll_index img&#39;</span><span class="p">).</span><span class="nx">trigger</span><span class="p">(</span><span class="s2">&quot;click&quot;</span><span class="p">)},</span> </span><span id="L-3"><a name="L-3"></a> <span class="mi">6000</span><span class="p">);</span> </span></pre></div> </td></tr></table>
intervalo, set, tiempo, trigger

Python

Singleton trigger

1
2
3
4
5
6
7
8
class Foo(int):
    shared_state = {'current': 0}
    def __new__(cls):
        return int.__new__(cls, cls.shared_state['current'])              
    
    def __init__(self):
        self.shared_state['current'] = abs(self.shared_state['current'] - 1)
        self.__dict__ = self.shared_state
https://snipt.net/embed/b72d490b985e11918daabfecc468c83a/
https://snipt.net/raw/b72d490b985e11918daabfecc468c83a/
b72d490b985e11918daabfecc468c83a
python
Python
8
2016-09-27T07:29:17
True
False
False
/api/public/snipt/31485/
singleton-trigger
<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="k">class</span> <span class="nc">Foo</span><span class="p">(</span><span class="nb">int</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="n">shared_state</span> <span class="o">=</span> <span class="p">{</span><span class="s">&#39;current&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">}</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">def</span> <span class="nf">__new__</span><span class="p">(</span><span class="n">cls</span><span class="p">):</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="nb">int</span><span class="o">.</span><span class="n">__new__</span><span class="p">(</span><span class="n">cls</span><span class="p">,</span> <span class="n">cls</span><span class="o">.</span><span class="n">shared_state</span><span class="p">[</span><span class="s">&#39;current&#39;</span><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="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> </span><span id="L-7"><a name="L-7"></a> <span class="bp">self</span><span class="o">.</span><span class="n">shared_state</span><span class="p">[</span><span class="s">&#39;current&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">abs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">shared_state</span><span class="p">[</span><span class="s">&#39;current&#39;</span><span class="p">]</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> </span><span id="L-8"><a name="L-8"></a> <span class="bp">self</span><span class="o">.</span><span class="n">__dict__</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">shared_state</span> </span></pre></div> </td></tr></table>
borg, pattern, python, trigger
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.