2011-07-26 3 views
0

어떻게 생각하나요?Jquery를 사용하여 비활성 div 클래스를 변경하십시오.

기본적으로 div 목록에서 첫 번째 div에 강조 표시 (활성 클래스 지정)하는 menue가 있습니다. 내가해야 할 일은 다음과 같습니다. 부모 div (다른 div, 목록이 나열되어 있음) 내에있는 동안 정상적인 호버 액션이 있습니다. 부모 div를 떠나면 마지막으로 강조 표시된 div는 활성 상태로 유지됩니다. 이해가 되니? 좀?

여기까지 제가 지금까지 있습니다. catListInner1은 다른 div가 그룹화 된 상위 div입니다.

var aCl = jQuery.noConflict(); 
aCl(document).ready(function() { 

    //takes the initial active class off of the first div. 
aCl("#catListInner1").live({ 
    mouseenter: function() { 
     aCl("#catListInner1 div:first").removeClass().addClass('catListOther'); 
    } 

}); 


aCl(".catListOther").live({ 
    mouseenter: function(e) { 
    // aCl("#catListInner1 div:first-child").removeClass('catListAct'); 
     aCl(this).removeClass().addClass('catListAct'); 
    }, 
    mouseleave: function(e){ 
     aCl(this).removeClass().addClass('catListOther'); 
    }, 
}); 
}); 
+0

'aCl' 대신'$'또는'jQuery'의 결국 무엇? 그것은 매우 혼란 스럽습니다. '$'를 내부에서 사용할 수 있도록 함수로 감싸는 것이 어떨까요? '(function ($) {...}) (jQuery.noConflict());' – ThiefMaster

답변

0

이 나를 위해 일 ::

var aCl = jQuery.noConflict(); 
aCl(document).ready(function() { 
var currentId 

aCl(".catListOther").live({ 
    mouseenter: function(e) { 

      aCl('.catListAct').not(aCl(this)).removeClass().addClass('catListOther'); 
     aCl(this).removeClass().addClass('catListAct'); 
     currentId = aCl(this).attr('id'); //get the ID of the last div you visited 
    } 
}); 

aCl(".catListAct").live({ 
    mouseleave: function(e){ 
     aCl(this).removeClass().addClass('catListOther'); 

    }, 
}); 

aCl('#catList').live('mouseleave', function() { 
    aCl("#" + currentId).removeClass().addClass('catListAct'); 
      //when leaving parent div, add the class back to the last div you visited in the list 
}); 
}); 
1

나는이 권리를 이해하고 있는지 알고,하지만 당신이 원하는 것은 (이 경우 div) 호버에 요소를 강조하고, 같은 클래스의 다른 요소를 가져 경우에만이 강조 표시를 제거하지 마십시오 ? 그런 경우가 있다면, 여기에 내가 할 줄 무엇 : 이것이 무엇을

$('element').mouseenter(function(){ 
    $('element.class').removeClass('class'); 
    $(this).addClass('class'); 
}); 

는 모든 요소에서 호버 클래스를 제거하고 현재 유혹 요소에 적용됩니다. 마우스가 현재 요소를 벗어나면 아무 일도 일어나지 않습니다.

관련 문제