Fancybox 2 and Swipe Slider do not work together

I want to create a fancybox with the Swipe image slider inside. By following the instructions in the how-to page of fancybox, I create a hidden div where my slider will be put.

<div style="display:none">
  <div id="hidden" >
    <div id="mySwipe" class='swipe'>
      <div class='swipe-wrap'>
        <div><b>0</b></div>
        <div><b>1</b></div>
        <div><b>2</b></div>
      </div>
    </div>
    <div style='text-align:center;padding-top:20px;'>
      <button onclick='mySwipe.prev()'>prev</button>
      <button onclick='mySwipe.next()'>next</button>
    </div>
  </div>
</div>

Now I use such hidden content to populate a fancybox:

<p align="center"><a class="fancybox" href="#hidden">Click me</a></p>

Unfortunately that has some problem I have the slider with empty (or hidden?) content. In other words I am not getting the slideshow 0 -> 1 -> 2.

I suppose that this problem is caused by the 'display:none' style. In fact if I take this out, the slideshow is working, but it shows the hidden content and I don't want this.

Here I report you the head of my html:

<!-- Add JQuery -->
<script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>

<!-- Add Swipe Slider -->
<script src="js/slider/swipe.js"></script>
<style>
/* Swipe 2 required styles */


.swipe {
    overflow: hidden;
    visibility: hidden;
    position: relative;
}
.swipe-wrap {
    overflow: hidden;
    position: relative;
}
.swipe-wrap > div {
    float: left;
    width: 100%;
    position: relative;
}

/* END required styles */
</style>

<!-- Add Fancybox -->
<link rel="stylesheet" href="js/fancybox/source/jquery.fancybox.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/fancybox/source/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    $(".fancybox").fancybox();
    var elem = document.getElementById('mySwipe');
    window.mySwipe = Swipe(elem, {});
    });
</script>

Solution 1:

You can try to set instead of display:none

<div style="position:absolute; left:-5000px;">

In this way the result is similar as display:none (the content of the div is not visible) and you should avoid the described problem