Thanks for seeing my question. I am using wp-pro-quiz plugin for quiz. I want to know that how can I pause the timer if the window is not in focus or is blur and resume it when it is back to focus.? My code:
var timelimit = (function() {
var _counter = config.timelimit;
var _intervalId = 0;
var instance = {};
instance.stop = function() {
if(_counter) {
window.clearInterval(_intervalId);
globalElements.timelimit.hide();
}
};
instance.start = function() {
var x;
if(!_counter)
return;
var $timeText = globalElements.timelimit.find('span').text(plugin.methode.parseTime(_counter));
var $timeDiv = globalElements.timelimit.find('.wpProQuiz_progress');
globalElements.timelimit.show();
$.winFocus(function(event) {
console.log("Blur\t\t", event);
},
function(event) {
console.log("Focus\t\t", event);
x = _counter * 1000;
});
var beforeTime = +new Date();
_intervalId = window.setInterval(function() {
var diff = (+new Date() - beforeTime);
var elapsedTime = x - diff;
if(diff >= 500) {
$timeText.text(plugin.methode.parseTime(Math.ceil(elapsedTime / 1000)));
}
$timeDiv.css('width', (elapsedTime / x * 100) + '%');
if(elapsedTime <= 0) {
instance.stop();
plugin.methode.finishQuiz(true);
}
}, 16);
};
return instance;
})();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire