Last active
August 29, 2015 14:16
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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