2016-12-16 66 views

回答

1

這是一個簡單的任務,涉及只是一個mousedownmouseup事件處理程序,並setIntervalclearInterval一個電話:

function thingToDoWhenTheButtonIsPressed() { 
    console.log('something'); 
} 

var mousedownInterval; 

map.on('mousedown', function() { 
    mousedownInterval = setInterval(thingToDoWhenTheButtonIsPressed, 500); 
}); 

map.on('mouseup', function() { 
    clearInterval(mousedownInterval); 
}); 

你可以看到一個working example here

不要忘記諮詢Leaflet documentation和MDN的documentation about window.setInterval()about window.clearInterval()