Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The easiest way to bind fancybox (v1.3.x) to dynamically added elements is:</p> <p>1: Upgrade to jQuery v1.7.x (if you haven't yet)</p> <p>2: Set your script using <a href="http://api.jquery.com/on/">jQuery API <code>on()</code></a> + the <code>focusin</code> event. </p> <p>To make it work you need to find the <code>parent</code> element of your elements with <code>class="ajaxFancyBox"</code> as per your code above (or the <code>parent</code> of the <code>parent</code> as you need it) and attach <code>jQuery on()</code> to it so for example, having this html:</p> <pre><code>&lt;div id="container"&gt; &lt;a class="ajaxFancyBox" href="image01.jpg"&gt;open image 01&lt;/a&gt; &lt;a class="ajaxFancyBox" href="image02.jpg"&gt;open image 02&lt;/a&gt; &lt;/div&gt; </code></pre> <p>.. we will apply <code>on()</code> and <code>focusin</code> event to the element with <code>id="container"</code> (the <code>parent</code>) as in the example above, like:</p> <pre><code>$("#container").on("focusin", function(){ $("a.ajaxFancyBox").fancybox({ // fancybox API options here 'padding': 0 }); // fancybox }); // on </code></pre> <p>You can apply any fancybox option as you need. Additionally you may have different scripts for different type of content (inside the <code>on()</code> method) like:</p> <pre><code>$("#container").on("focusin", function(){ $("a.ajaxFancyBox").fancybox({ // fancybox API options here 'padding': 0 }); // fancybox $("a.iframeFancyBox").fancybox({ // fancybox API options here 'padding': 0, 'width': 640, 'height': 320, 'type': 'iframe' }); // fancybox }); // on </code></pre> <p><strong>IMPORTANT</strong>: the example above won't work like that on Chrome. The <strong>workaround</strong> is to add the <code>tabindex</code> attribute to all of your elements bound to fancybox like</p> <pre><code>&lt;div id="container"&gt; &lt;a tabindex="1" class="ajaxFancyBox" href="image01.jpg"&gt;open image 01&lt;/a&gt; &lt;a tabindex="1" class="ajaxFancyBox" href="image02.jpg"&gt;open image 02&lt;/a&gt; &lt;/div&gt; </code></pre> <p>that solves the issue and will work (as far as I know) in most browsers including IE7+.</p> <p><a href="http://picssel.com/playground/jquery/jQueryON_13dec11.html">See my demo page here</a></p> <p><strong>UPDATE: March 07, 2012.</strong></p> <p>I was told that this method only works when you add new content to the page but not when you replace the content of the page.</p> <p>The method actually works on either of the two scenarios mentioned above. Just make sure that the new replacing content is also loaded inside the container where you applied the <code>.on()</code> method.</p> <p><a href="http://picssel.com/playground/jquery/jQueryONreplacingContent_07mar12.html">See demo</a></p> <p>The <code>tabindex</code> workaround for Chrome also applies.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload