treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Anything Slider stopping autoPlay

  • Inside my anything slider, I have links that open up lightbox. The problem with the way anything slider is set up is that when I click the link inside the slider, the lightbox opens up with the content but the anything slider keeps on looping in the background. How can I stop the slider when a user clicks on a link inside of it?
  • Hi Thedark_master!

    Before you open the lightbox, just add this bit of script to stop the slide show. Make sure your slider is targeted, I'm using "#mySlider" in the example.

    $('#mySlider').data('AnythingSlider').startStop(); // this stops the slideshow
  • I apologize for the late reply, I was waiting for an email to be sent when someone replied to my question. So I am not that familiar with how to link javascript code to my link inside the document. Can you help me out with this? So for example if my code for the link is this:
    <a class="video" href="http://www.link.com&quot; title="title"></a>
    How would I link the JS code you gave me?
  • Add this code somewhere on your page. Just make sure the slider ID matches:
    <script type="text/javascript">
    $(document).ready(function(){
    $('a.video').click(function(){
    $('#mySlider').data('AnythingSlider').startStop(); // this stops the slideshow
    });
    });
    </script>
  • thank you so much!
  • My anything slider is placed in a div id="main". I have the function below set to stop the slide when click are done in main.. The slider does not pause and keeps playing.

    $(document).ready(function(){ //Pause Slider when Playing $('#main').click(function(){ $('#slider1').data('AnythingSlider').startStop(); //stop the slideshow //alert("stop slider."); }); });

    is

     $('#slider1').data('AnythingSlider').startStop(); //stop the slideshow 
    

    supposed to stop the slide.. I am I missing something? Please Help.