I create a presentation with this javascript framework http://lab.hakim.se/reveal-js/#/ and when certain slide is appearing I want to execute function stats(), which display some data from API every 5 seconds, but only when this slide is appearing
function stats(){
$.ajax({
type: "GET",
url: url_survey,
dataType: "json",
success :
function (data) {
//some code to display data
},
error:
//some code
});
}
in HTML file I have this:
<section>
<div id="stats">
</div>
</section>
how can I do it? I wrote this code, but it works always, not only when slide appear
function check(){
if($("#stats").is(":visible"))
stats();
}
check();
setInterval(function(){check()}, 2000);