回答編集履歴
2
ソース修正
    
        answer	
    CHANGED
    
    | 
         @@ -10,7 +10,7 @@ 
     | 
|
| 
       10 
10 
     | 
    
         
             
            ここでclearIntervalに渡すintervalIDはsetIntervalの戻り値から指定しないといけません。
         
     | 
| 
       11 
11 
     | 
    
         
             
            ```javascript
         
     | 
| 
       12 
12 
     | 
    
         
             
            function fadeTo(count, a){
         
     | 
| 
       13 
     | 
    
         
            -
              setInterval(function(){
         
     | 
| 
      
 13 
     | 
    
         
            +
              var intervalid = setInterval(function(){
         
     | 
| 
       14 
14 
     | 
    
         
             
                var current = new Date() - count;  // 経過時間を取得する(現在時刻 - クリック時の時刻)
         
     | 
| 
       15 
15 
     | 
    
         
             
                  if(current > 500){
         
     | 
| 
       16 
16 
     | 
    
         
             
                    clearInterval(intervalid);
         
     | 
1
ソースの修正
    
        answer	
    CHANGED
    
    | 
         @@ -1,19 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            clearIntervalの引数はsetIntervalしたときにわかるintervalIdです。
         
     | 
| 
       2 
2 
     | 
    
         
             
            よって、
         
     | 
| 
       3 
3 
     | 
    
         
             
            ```javascript
         
     | 
| 
       4 
     | 
    
         
            -
            function  
     | 
| 
      
 4 
     | 
    
         
            +
            function fadeTo(count, a){
         
     | 
| 
       5 
5 
     | 
    
         
             
              setInterval(function(){
         
     | 
| 
       6 
     | 
    
         
            -
                var current = new Date() - count;
         
     | 
| 
      
 6 
     | 
    
         
            +
                var current = new Date() - count;  // 経過時間を取得する(現在時刻 - クリック時の時刻)
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
7 
     | 
    
         
             
                  if(current > 500){
         
     | 
| 
       9 
8 
     | 
    
         
             
                    clearInterval(fadeOut);
         
     | 
| 
       10 
9 
     | 
    
         
             
            ```
         
     | 
| 
       11 
10 
     | 
    
         
             
            ここでclearIntervalに渡すintervalIDはsetIntervalの戻り値から指定しないといけません。
         
     | 
| 
       12 
11 
     | 
    
         
             
            ```javascript
         
     | 
| 
       13 
     | 
    
         
            -
            function  
     | 
| 
      
 12 
     | 
    
         
            +
            function fadeTo(count, a){
         
     | 
| 
       14 
     | 
    
         
            -
               
     | 
| 
      
 13 
     | 
    
         
            +
              setInterval(function(){
         
     | 
| 
       15 
     | 
    
         
            -
                var current = new Date() - count;
         
     | 
| 
      
 14 
     | 
    
         
            +
                var current = new Date() - count;  // 経過時間を取得する(現在時刻 - クリック時の時刻)
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
15 
     | 
    
         
             
                  if(current > 500){
         
     | 
| 
       18 
16 
     | 
    
         
             
                    clearInterval(intervalid);
         
     | 
| 
       19 
17 
     | 
    
         
             
            ```
         
     |