Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flexslider Add Slide (Ajax Content)

I'm writing a page where have a 4 slides with a of lot image content. To improve loading speed we want to only load the first slide. Then after its loaded we would get the rest through ajax calls and add them as slides.

Flexslider V2 has an .addSlide function for this, however I keep getting slider.addSlide is not a function error.

Any help would be much appreciated. Thanks

Flexslider

Here's my code.

<!DOCTYPE html>
<html lang="en">
<head>

<link rel="stylesheet" href="_slider/flexslider.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
<script src="_slider/jquery.flexslider-v2-min.js"></script>

<script type="text/javascript">
$(window).load(function() {
     $('.flexslider').flexslider({

        animation: "slide", 
        slideshow: false, 
        controlNav: false, 
        controlsContainer: ".flex_wrap", 
        start: function(slider){

            //Load another slide and append it to the html
            $.get('landing_page_step1.html', function(data) {
              $('.slides').append(data);
            });

            //Tell flexslider to add this as a slide
            slider.addSlide(".step1", 1);     
        }

      });
 });    
</script>

</head>

<body class="landing_page">

<div class="flex_wrap">
  <div class="flexslider grid_12">
    <ul class="slides">
      <li>
              Slide One
      </li>
    </ul>
 </div>
</div>

</body>
</html>

[Update]

Its appears that if you only have one slide then flexsider doesn't accept these extra functions. By starting with two slides this idea works fine. It's most likely an error or intended feature of flexslider.

like image 414
dciso Avatar asked Oct 08 '22 06:10

dciso


1 Answers

I ran into this same issue just recently and I ended up looking at the source code and saw that the developers put in a check if the number of slides equals one (Line 882).

I just ended up commenting out that whole if statement and it started working when I only had one slide.

like image 80
bigwh00p Avatar answered Oct 13 '22 10:10

bigwh00p