2013-08-16 3 views
1

내 코드에 문제가 있습니다. 나는 'jq'라는 이름의 배경색을 가진 많은 클래스 요소를 가지고있다. 내가 떠듬적 거리는 배경색에 애니메이션을 적용한 다음 다시 원래 색상으로 되돌립니다. 여기서는 .css ('backgroundColor')가 지정된 div의 색상과 jq 클래스를 가져와야합니다. 대신 div 배경이 흰색으로 되돌아갑니다. 여기 내 코드는 : 여기jQuery .css ('backgroundColor') 문제

$(document).ready(function(){ 
      $(".jq").hover( 
      var bgcol = $(this).css('backgroundColor'); 
       function(){ 
        $(this).animate({  
        backgroundColor: "#EAEAEA", 
        color:"#333" 
        },trans); 
       }, 
       function() {  
        $(this).animate({ 
        backgroundColor:'bgcol', 
        color:"#888" 
        },trans); 
       });   
      }); 
+0

는 당신이 시도 않았다 텍스트가 – Constanta

답변

1

있습니다 구문 오류

$(document).ready(function(){ 
    $(".jq").hover( 
     function(){ 
      var bgcol = $(this).css('backgroundColor'); 
      $(this).animate({  
       backgroundColor: "#EAEAEA", 
       color:"#333" 
      }, trans).data('hoverbackground', bgcol); 
     }, 
     function() {  
      $(this).animate({ 
       backgroundColor: $(this).data('hoverbackground'), 
       //backgroundColor: "#EFEFEF", 
       color:"#888" 
      }, trans).removeData('hoverbackground'); 
     });   
}); 

데모 : Fiddle

+0

분류 조금 지저분 배경 색! 도와 주셔서 감사합니다 아룬 – user841760