-
Notifications
You must be signed in to change notification settings - Fork 380
Callbacks and Events
Sections: Callback options | API Arguments | API Functions | Examples
- Called at the same time that the
before_initialize
event triggers which occurs when the plugin initializes. - The only changes that have occurred at this point are:
- The
anythingSlider
object has been attached to theul
(theul
is the target of the anythingSlider code). - The class
anythingBase
was added to theul
. - The
ul
was wrapped in two divs (div.anythingSlider
anddiv.anythingWindow
).
- The
- Called at the same time that the
initialized
event triggers which occurs when the plugin has completed its initialization. - This event may occur after the slideshow has initialized (
onSlideInit
).
- Called at the same time that the
slideshow_start
event triggers which occurs when a slideshow has started.
- Called at the same time that the
slideshow_stop
event triggers which occurs when the slideshow has stopped.
- Called at the same time that the
slideshow_paused
event triggers which occurs when the slideshow has paused due to mouseover. - This callback and event will still occur when the slideshow is paused while a youtube video is playing. The slideshow has paused but not due to mouseover.
- Called at the same time that the
slideshow_unpaused
event triggers which occurs when the slideshow has resumed because the slider has stopped being hovered over. - Note: this event will not trigger properly (matching the pause event) if the user clicks on any of the controls (navigation or play/stop link).
- Called at the same time that the
slide_init
event triggers which occurs when the script has been called to change pages. - This is triggered before the controls animate (see Navigation
toggleControls
). - The callback arguments for
currentPage
may not be set properly for pages on either end of the slider. ThecurrentPage
value for the last page will point to a clone of the first page when scrolling forward and conversely, thecurrentPage
value for the first page will point to the clone of the last page when scrolling backwards. If you need the target page, get it when the slide complete callback has triggered.
- Called at the same time that the
slide_begin
event triggers which occurs immediately before slide animation.
- Called at the same time that the
slide_complete
event triggers which occurs after the slide animation has completed.
- Called at the same time that the
slideshow_resized
event triggers which occurs whenever the slider has been resized, but only when theexpand
option istrue
.
When using any of the above callback functions/triggered events. These callback arguments will be available. If you name the callback argument "slider" as in the simplified examples below, then the listed arguments are available to use (use the callback examples for better examples).
-
API access :
var slider = $('#slider').data('AnythingSlider');
-
Callback option (
onSlideComplete
is the only callback without anevent
variable):onSlideComplete : function(slider){ ... }
-
Triggered event (The 'slide_complete' triggered event does have an
event
variable):$('#slider').bind('slide_complete', function(event, slider){ ... });
- jQuery object of the
ul
targeted when AnythingSlider was initialized.
- jQuery object of all pages (
li
), including cloned pages. - To target non-cloned pages, use
slider.$items.filter(':not(.cloned)')
- jQuery object of the entire AnythingSlider.
- It contains
slider.$el
and all the other objects (unless you appended the controls elsewhere, then useslider.$controls
).
- jQuery object of the AnythingSlider controls (includes navigation tabs and slideshow play/stop link).
- This targets the controls even if they are appended elsewhere (see
appendControlsTo
).
- Target page (non-cloned page) set before the slider animates.
- This variable is available during "slide_init", "slide_begin" and "slide_complete" events.
- jQuery object of the target page (non-cloned page).
- This is the same page as defined in
slider.targetPage
.
- Currently displayed page/slide number.
- Updated to the target page when the animation completes.
- jQuery object of the current page, it does not update until the "slide_complete" event.
- This is the same page as
slider.currentPage
.
- jQuery object of the previous page.
- This is the same page as
slider.$currentPage
until theslide_complete
event occurs, then it truly becomes the last page.
- Number of pages contained in the slider.
- This does not include cloned pages.
- Is true if the slideshow is currently playing.
- Is false when slideshow is paused, but true while videos are playing.
- Is true if the slider was being hovered when the event occurred.
- Access any of the slider options (e.g. slider.options.theme).
- Trying to set the options this way is possible, but may break the slider.
-
Call this function to update the slider with new or removed content.
-
This internal function is called when you call the plugin with no parameters:
$('#slider').anythingSlider();
. -
There are no parameters for this function.
-
Use it as follows:
$('#slider').data('AnythingSlider').updateSlider();
-
Call this function to advance the slider one page.
-
This internal function is called when clicking on the forward arrow, which is switched when
playRtl
istrue
. -
There is one parameter for this function,
autoplay
. When this option is true, the slider will allow a running slideshow to continue. -
Use it as follows:
$('#slider').data('AnythingSlider').goForward(); // stop slideshow, if playing $('#slider').data('AnythingSlider').goForward(true); // allow a slideshow to continue playing
-
Call this function to make the slider go back one page.
-
This internal function is called when clicking on the back arrow, which is switched when
playRtl
istrue
. -
There is one parameter for this function,
autoplay
. When this option is true, the slider will allow a running slideshow to continue. -
Use it as follows:
$('#slider').data('AnythingSlider').goBack(); // stop slideshow, if playing $('#slider').data('AnythingSlider').goBack(true); // allow a slideshow to continue playing
-
Call this function to change the current slide to any page.
-
This internal function is called when clicking on the navigation tabs.
-
There are four (4) parameters for this function:
page
,autoplay
,callback
,time
.-
page
sets the desired page -
autoplay
is a flag that tells the plugin to allow a slideshow to keep running. Set it totrue
to continue a slideshow, orfalse
or undefined to stop it. -
callback
is a callback function that is run after the desired page is in view. Set it tonull
or{}
if no callback is needed. -
time
is the animation time to use for this one time only.- Setting this time to
-1
will prevent theslide_init
,slide_begin
andslide_complete
events from being triggered. - Setting this to
0
will set the animation time to zero, but only in version 1.8.6+. Earlier versions will set a zero time to the defaultanimationTime
.
- Setting this time to
-
-
Use it as follows:
// gotoPage( page, autoplay, callback, time ) $('#slider').data('AnythingSlider').gotoPage(1); // go to page 1 $('#slider').data('AnythingSlider').gotoPage(2, true); // go to page 2 & allow a slideshow to continue playing $('#slider').data('AnythingSlider').gotoPage(2, false, function(){ alert('done'); }); // go to page 2, stop slideshow & alert when page 2 is in view $('#slider').data('AnythingSlider').gotoPage(3, '', {}, -1); // go to page 3, stop slideshow (use '' or false), no callback and make it instant $('#slider').data('AnythingSlider').gotoPage(3, false, null, 0); // go to page 3, stop slideshow, no callback, set animation time of zero (in 1.8.6+) with triggered events
of course the callback function can do more :P
$('#slider').data('AnythingSlider').gotoPage(2, false, function(slider){ slider.$currentPage.find('form')[0].reset(); // reset the form on the current page });
-
Call this function to start or stop the slideshow.
-
This internal function is called when clicking on the start/stop slideshow button.
-
There are two parameters for this function,
playing
andpaused
.-
playing
is set totrue
to start a slideshow. Set tofalse
to stop it. -
paused
is used when hovering over AnythingSlider to allow the internal timer to keep running. This may not be useful, but I've included it here to be complete.
-
-
Use it as follows:
$('#slider').data('AnythingSlider').startStop(); // stop slideshow $('#slider').data('AnythingSlider').startStop(true); // start a slideshow
-
Call this function to slide the navigation (only if the
toggleControls
option istrue
) and arrows (only if thetoggleArrows
option istrue
) in and out of view. -
This internal function is called when hovering the slider or changing slides.
-
There is one parameter for this function,
toggle
. Whentrue
the elements will become visible, and whenfalse
they will hide. -
Use it as follows:
$('#slider').data('AnythingSlider').slideControls(); // hide controls/arrows (if options allow) $('#slider').data('AnythingSlider').slideControls(true); // show controls/arrows (if options allow)
-
Call this function to make the selected slider active. All it does is adds the class
activeSlider
to the current slider. -
Only the active slider will change slides when the user presses the keyboard arrow keys, if the
enableKeyboard
option istrue
. -
This internal function is called whenever the slider is actively changed (not during a slideshow).
-
There are no parameters for this function.
-
Use it as follows:
$('#slider').data('AnythingSlider').makeActive();
The FX extension essentially binds to the slide_init
and slide_complete
events to add the animation effects for each panel.
$('#slider1').bind('slide_complete', function(event, slider){
console.debug( 'You are on page #' + slider.currentPage );
// Do something else
});
This code binds to all events to reports them to the display panel and the console (if available). Add spaces between each bound event (not commas!).
// Report Events to console & features list
$('.anythingSlider').bind('slideshow_start slideshow_stop slideshow_paused slideshow_unpaused slide_init
slide_begin slide_complete',function(event, slider){
// show object ID + event (e.g. "slider1: slide_begin")
var txt = slider.$el[0].id + ': ' + event.type + ', now on panel #' + slider.currentPage;
$('#status').text(txt);
// added window.console.firebug to make this work in Opera
if (window.console && window.console.firebug){ console.debug(txt); }
});
$('#slider').anythingSlider({
onSlideBegin : function(event, slider){
alert('Welcome to Slide #' + slider.currentPage);
},
// "onSlideComplete" is the only callback without an "event" variable
onSlideComplete : function(slider){
alert('Welcome to Slide #' + slider.currentPage);
}
});
$('#slider').anythingSlider(4, function(slider){
alert('Now on page ' + slider.currentPage);
});
Callback function that updates the windows hash tag with the current panel (this only works for a single slider on the page)
$('#slider2').bind('slide_complete', function(event, slider){
window.location.hash = '#&panel' + slider.runTimes + '-' + slider.currentPage;
});