malsup / cycle2

2nd gen cycling
899 stars 239 forks source link

Adding and Centering New Slides after Initialisation #805

Open Funkiegh opened 7 years ago

Funkiegh commented 7 years ago

Hi, I've got a simple slideshow that reads the contents of a server folder through an Ajax call and returns any new files it finds. It's called at page load and subsequently at 5 second intervals. I use a session variable to keep track of the currently used files. It works nicely except that after initialization any new slides added are not centered... only when I refresh the page and all files are again loaded on initialization. Is there a way to call the centerHoriz and centerVert at the same time as adding the new slides? Here is my code: `

<script src="http://malsup.github.io/jquery.cycle2.center.js"></script>

<script type="text/javascript">

  function loadSlides() {

    $.ajax({
      type: "GET",
      url: "http://www.kateandmikewedding.info/wp-content/themes/wedding/load.php"
    }).done(function(response) {
      var temp_images = eval("(" + response + ")");
      for(ti in temp_images){
        $('.slideshow').cycle('add','<img src="http://www.kateandmikewedding.info/uploading/server/php/files/display/' + temp_images[ti] + '" alt="">');
      }
    });
  }

  window.setInterval(function(){loadSlides()}, 5000);

  jQuery(document).ready(function($){
    loadSlides();
    $('.slideshow').cycle(
    {
        next: '.slideshow'
    });
  });

</script>

`