Search code examples
jqueryjplayeranythingslider

AnythingSlider Detect Current Slide


I wrote a short script that detects what slide is being displayed on the AnythingSlider plugin and then shows an alert if the current panel matches the panel in the script. However, it only works if I change the startPanel (the first panel displayed on page load) to the one in the script (2). Not sure why this is happening.

    $(document).ready(function(){   

    var current = $('#slider').data('AnythingSlider').currentPage; // returns page #    

        $(".arrow a").click(function (){    

            if (current == 2)
        {
            alert("Welcome");
        }   

        });

    });

Solution

  • The currentPage needs to be checked at the time of the click... try this:

    $(document).ready(function(){   
    
        $(".arrow a").click(function (){    
    
            if ($('#slider').data('AnythingSlider').currentPage == 2)
        {
            alert("Welcome");
        }   
    
        });
    
    });