2011-09-12 4 views
0

これは簡単だと思っていましたが、私は短くする方法と長い方法のどちらかと思われます。jQuery - 3分で

私は、これは私が* 1000年3、3 * 60、300、私は3000を試してみました働くだろうと思ったので、

var timeout = 30*1800; 

にカウントダウンされ3minutes 後にユーザーに署名しようとしています

これは私が実行しようとしています関数である、

function loadidle(){ 

      var timeout = 180000; 
      //alert(timeout); 

      $(document).bind("idle.idleTimer", function(){ 

       logout(); 

      }); 


      $.idleTimer(timeout); 
} 
+0

1000年* 60(1000のミリ秒、回60秒、回3分) – galchen

答えて

1

単純なタイマーが必要です。多くの品種があります。ここでクラスとして素敵に抽象化した汚れた安い例があります。 .reset()を呼び出して、タイマーを「続行」することができます。

function Timeout(seconds, callback){ 
    this.length = seconds * 1000; 
    this.callback = callback; 
    this.start(); 
} 
Timeout.prototype = { 
    start: function(){ 
     var self = this; 
     this.stop(); 
     this.timer = setTimeout(function(){ 
      self.complete(); 
     },this.length); 
    }, 
    stop: function(){ 
     if (this.timer) clearTimeout(this.timer); 
     this.timer = null; 
    }, 
    complete: function(){ 
     if (this.callback) this.callback(); 
     this.stop(); 
    }, 
    reset: function() { 
     this.stop(); 
     this.start(); 
    } 
} 

スタート新しいタイマー:* 3

var timer = new Timeout(3 * 60, logout); 
timer.reset(); // refresh the timer 
timer.stop(); // cancel the timer 
0

かなり確信してJS(したがって、jQueryの)あなたは* 1000年3 * 60を望むことがありますので、ミリ秒を使用します。

+0

私は '秒' と「分を使用して、それをしていますがタグは本当にベストプラクティスではありません! –