2012-11-05 5 views
0

이것은 내가 원하는 것입니다. div에서 마우스를 가져갈 때 시간 초과가 발생하고 다시 div 위로 가져 가면 취소됩니다.setTimeout/Cleartimeout을 사용할 때 예기치 않은 토큰 ILLEGAL

내가 cancelfunction을 제거하면 코드가 작동합니다. 따라서 div를 표시하고 숨기는 것이 좋습니다.

내 코드입니다 : 직후 줄에 나타납니다

Uncaught SyntaxError: Unexpected token ILLEGAL

이 수 window.clearTimeout(timeoutID);

누구나 난을 확인하려면 다음을 참조하십시오 :

$(document).ready(function() 
    { 
     var timeoutID; 
     function clearAlert() 
     { 
      window.clearTimeout(timeoutID); 
     }​ 

     if ($('.txtVote').text() == "Avgi stemme") 
     { 
      $('#starInfo').hover(
      function() 
      { 
       clearAlert(); 
       $('#CarDetailsButtons').css('right', '10px'); 
       $('#voteStars').show(); 
      }, 
      function() 
      { 
       console.log("hide iniated"); 
       timeoutID = window.setTimeout(hideStars, 2000); 
       console.log("hide executed"); 
      });  
     } 

     function hideStars() 
     { 
      console.log("hideStars ran"); 
      $('#CarDetailsButtons').css('right', '45px'); 
      $('#voteStars').hide(); 
     } 
}); 

그리고,이 내 오류입니다 잘못하고있는거야? :)

편집이 : * 그래서 *

작품은 내가 복사 붙여 넣기 버그의 일종했다 보인다. 필자는 이전과 마찬가지로 clearAlert 함수를 수동으로 작성했으며 현재 작동합니다.

모든 정보를 제공해 주셔서 감사합니다.

+2

'var timeouteId; 대'timeoutID' - 변경 중 하나 – mplungjan

+0

작동하지 않았다 :(그러나 나는 코드를 업데이트했다. 여전히 같은 오류가 발생했다. 나는 심지어 var timeoutID가 필요하다고 생각하지 않는다; – sindrem

+1

var를 전역 범위 : window.timeoutID = ""; – mplungjan

답변

0

이 같은 준비 문서의 외부에서 기능을 이동할 수 제안 :

function hideStars() 
    { 
     console.log("hideStars ran"); 
     $('#CarDetailsButtons').css('right', '45px'); 
     $('#voteStars').hide(); 
    } 

function clearAlert() 
    { 
     window.clearTimeout(timeoutID); 
    }​ 

$(document).ready(function() 
    { 
    var timeoutID; 


    if ($('.txtVote').text() == "Avgi stemme") 
    { 
     $('#starInfo').hover(
     function() 
     { 
      clearAlert(); 
      $('#CarDetailsButtons').css('right', '10px'); 
      $('#voteStars').show(); 
     }, 
     function() 
     { 
      console.log("hide iniated"); 
      timeoutID = window.setTimeout(hideStars, 2000); 
      console.log("hide executed"); 
     });  
    } 


}); 
+0

edit for my solution. 어쨌든 고마워요 :) – sindrem

+0

위대한 편집 ....... 그런데. – Jai

2

이 시도 :

var that = this; 
that.timeoutID = null; 

... 

that.timeoutID = ... 

또는 VAR를 선언해야

timeoutID = NULL; 글로벌. 따라서 $ (document) .ready의 함수 컨텍스트가 아닌 gloabl 컨텍스트에서 var를가집니다.

가장 좋은 해결책은 타이머가있는 약간의 js 클래스를 작성하는 것입니다. 그래서 당신은 세계적인 갈등이 없다.

인사!

관련 문제