0

ユーザーがマウスの使用をやめた後にのみイベントをトリガーする方法は? ズーム中に ajax を呼び出したくないため (たとえば、6 回のズームインで 6 つのイベントがトリガーされますが、ズームインが完了したときに必要なイベントは 1 つだけです)。

この関数は実行を遅らせますが、それでもすべてのイベントを実行します...

  google.maps.event.addListener(map, 'center_changed', function() {
    // 3 seconds after the center of the map has changed
    window.setTimeout(function() {
      myfunction());
    }, 3000);
  });
4

4 に答える 4

0
var lastTriggeredTime;  
google.maps.event.addListener(map, 'center_changed', function() {
    // 3 seconds after the center of the map has changed
    window.setTimeout(function() {
      //set last Triggered Time to now (user is still zooming)
      lastTriggeredTime = (new Date()).getTime();
      myfunction());
    }, 1000);
  });
var myfunction = function(){
  if(lastTriggeredTime + 3000 < (new Date()).getTime()){
    //3 seconds has elapsed since last center_changed event got fired.
  }
}
于 2013-01-22T22:56:01.917 に答える
0

offsetLeft と offsetTop を使用してマウス カーソルの x と y の位置を計算し、短時間変更されなかった後にイベントを実行できますか?

于 2013-01-22T22:42:23.820 に答える
-1

私はこの問題を解決しました:

トリガーがトリガーされるたびに、私はこれを行います:clearInterval(trigerFunctionVar); trigerFunctionVar=null;そして、新しい間隔をに追加しますtrigerFunctionVar

于 2013-01-28T20:47:31.910 に答える