Skip to content

Instantly share code, notes, and snippets.

@hktang
Last active August 29, 2015 14:16
Show Gist options
  • Save hktang/f26a06326bc5a59f89bc to your computer and use it in GitHub Desktop.
Save hktang/f26a06326bc5a59f89bc to your computer and use it in GitHub Desktop.
Add a quick and clean autoplay loop for your display/exhibit using TimelineJS
/**
* Loop your Timeline.js timeline, for your display/exhibit.
* @Inspiredby discussions at:
* https://groups.google.com/forum/#!topic/verite-timeline/h9fOiKCqGZs
* Demo at: http://www.apn-gcr.org/visual/timeline/
*/
(function($){
var delay = 10000; // interval between slides, in miliseconds
var loop = true; // play timeline in loops if set to true
/** Triggers a click on the "Next" link at the preset interval,
* and on the "Back home" link if the "Next" link is hidden
* (i.e. end of Timeline).
*/
function autoplay(){
if ( $('.nav-next').css('display') == 'none' ) {
if ( loop == true ) {
$('.back-home').trigger('click');
}
}else {
$('.nav-next').trigger('click');
}
}
/** In your HTML, add the following anchor as a control:
* <a hre="#" id="autoplay">Start autoplay</a>
*/
(function(){
$('#autoplay').click(function(){
var playStatus = $('#autoplay').text();
if (playStatus == "Start autoplay" ){
$('#autoplay').text( "Stop autoplay" );
startAutoPlay = setInterval(function(){autoplay()}, delay);
}else{
$('#autoplay').text( "Start autoplay" );
clearInterval ( startAutoPlay );
}
});
})();
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment