Thank you for your answer.
I don't know where to define/change the bStop variable. Inside the loop? I tried it with a recursiv function, but clicking stop still doesn't affect the animation. here is my new code:
- $(document).ready(function () {
var years = [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999];
var stopvalue = -1;
var position = 0;
$("#stop").click(function() {stopvalue = -1;});
$("#start").click(function() {showMap(stopvalue=1, position);});
function showMap (stopvalue, position) {
if (stopvalue == 1) {
if (position > years.length) {
return false;
}
setTimeout(function() {
$('#movie').text(years[position]);
}, 1000*position);
position++;
showMap(stopvalue, position);
}
else if (stopvalue == -1) {
return false;
}
}
});