我有以下代码,它工作正常,直到我点击#play 按钮。我假设这是因为 var intID 设置在另一个地方,并且当我 window.clearInterval() 它时它不在同一个范围内......我该如何解决这个问题?顺便说一句,这是 Google Maps API 版本 3
function intervalTrigger(){
return window.setInterval(function(){
placement++;
if(placement >= markers.length){placement = 0;}
google.maps.event.trigger(markers[placement], "click");
}, 5000);
};
var intID = intervalTrigger();
$('#map_canvas').click(function(){window.clearInterval(intID);});
$('a[href=#nextmarker]').live('click',function(){
placement++;
if(placement >= markers.length){placement = 0};
google.maps.event.trigger(markers[placement], "click");
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});
$('a[href=#prevmarker]').live('click',function(){
placement--;
if(placement == -1){placement = markers.length-1}
google.maps.event.trigger(markers[placement], "click");
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});
$('a[href=#play]').live('click',function(){
$('a[href=#play]').replaceWith('<a href="#pause">Pause</a>');
var intID = intervalTrigger();
return false;
});
$('a[href=#pause]').live('click',function(){
window.clearInterval(intID);
$('a[href=#pause]').replaceWith('<a href="#play">Play</a>');
return false;
});