2015-12-09 54 views
0

我發現如何在超時時設置功能。但它不在這個JQUERY函數中工作。請幫助我。這裏去jquery代碼:如何在超時時設置Jquery函數?

$(function() {   
      var $wrapper= $('#fc-wrapper'), 
       $handle = $wrapper.children('div.fc-handle-pull');     

      $(function(event) {    
       ($handle.data('opened')) ? close() : open();     
      }); 

      $wrapper.hammer().bind('dragend', function(event) { 
       switch(event.direction) { 
        case 'right': open(); break; 
        case 'left': close(); break; 
       } 
      }); 

      function open() { 
       $wrapper.addClass('fc-wrapper-open'); 
       $handle.data('opened', true); 
      } 

      function close() { 
       $wrapper.removeClass('fc-wrapper-open'); 
       $handle.data('opened', false); 
       } 

     }); 

請告訴我如何在超時設置此功能。在此先感謝

+1

你能告訴我們你的嘗試嗎? – bcap

+1

'$(function(event){$ {handle.data''沒有意義讓jQuery包裝它 – epascarello

+0

你想要暫停嗎? – epascarello

回答

0

我解決了這個問題我自己。這裏是代碼:

setTimeout(function(){ 

      var $wrapper= $('#fc-wrapper'), 
       $handle = $wrapper.children('div.fc-handle-pull');     

      $(function(event) {    
       ($handle.data('opened')) ? close() : open();     
      }); 

      $wrapper.hammer().bind('dragend', function(event) { 
       switch(event.direction) { 
        case 'right': open(); break; 
        case 'left': close(); break; 
       } 
      }); 

      function open() { 
       $wrapper.addClass('fc-wrapper-open'); 
       $handle.data('opened', true); 
      } 

      function close() { 
       $wrapper.removeClass('fc-wrapper-open'); 
       $handle.data('opened', false); 
       } 


     } , 2000); 
+0

是的,你明白了 – csum

0

如果你只是想這對超時後執行的,只是包裝中的代碼setTimeout

$(function() { 
    // call setTimeout with a function and a timeout length in milliseconds 
    var waitLength = 1000; // ms 
    var timer = setTimeout(function() { 

     var $wrapper= $('#fc-wrapper'), 
      $handle = $wrapper.children('div.fc-handle-pull');     

     // no need to wrap this in $(function(){...}) since you already 
     // did that on line 1 
     $handle.data('opened') ? close() : open(); 

     $wrapper.hammer().bind('dragend', function(event) { 
      switch(event.direction) { 
       case 'right': open(); break; 
       case 'left': close(); break; 
      } 
     }); 

     function open() { 
      $wrapper.addClass('fc-wrapper-open'); 
      $handle.data('opened', true); 
     } 

     function close() { 
      $wrapper.removeClass('fc-wrapper-open'); 
      $handle.data('opened', false); 
     } 

    }, waitLength); // end setTimeout call 

}); 
+0

我已經解決了它自己。謝謝反正 –