【发布时间】:2016-12-06 11:58:21
【问题描述】:
我正在尝试使用 Angular js $timeout 函数创建问题幻灯片,我能够实现它并且它工作得很好,但是当我尝试刷新幻灯片以便它可以重新开始时,刷新仅适用于第一张幻灯片,因为其他幻灯片不适用于超时延迟时间 下面是我的代码,main函数和recall函数。
$scope.callTime = function() {
q_len = questions.length;
$timeout(function () {
//checking if the question index is still valid
if (q_indy < q_len) {
slides = questions[q_indy].pictures;
len = slides.length;
console.log(indy);
$scope.currentQuestion = questions[q_indy];
f_time = parseInt(slides[indy].time_frame);
//getting the specific time needed to run this particular slide
r_time = f_time - initialTime;
if (indy < len) {
f_time = parseInt(slides[indy].time_frame);
var interval = slides[indy].picture_url;
indy++;
console.log(q_indy + " " + indy + " " + r_time);
//changing to the current picture so it can run for the given time
$scope.image = $scope.url.url + interval;
if (indy == len) {
//checking if the question's slides is out of index so the next question should be loaded
q_indy++;
indy = 0;
initialTime = f_time;
console.log(q_indy + " " + indy + " " + r_time);
$scope.callTime();
}
else {
//if the slide index is active the next slide should be loaded then
initialTime = f_time;
$scope.callTime();
}
//console.log($scope.url.url + interval);
}
}
}, r_time);
//time();
}
$scope.refresh = function () {
$timeout.cancel($scope.callTime);
q_indy = 0;
indy = 0;
initialTime = 0;
r_time = 0;
len = 0;
q_len = 0;
$scope.callTime();
var e = document.getElementById('myTune');
//e.pause();
e.currentTime = 0;
//e.play;
};
【问题讨论】:
标签: javascript angularjs timeout