안녕하세요 저는이 코드를 사용하여 패딩에 애니메이션이있는 링크 목록을 사용합니다. 그 패딩을 유지하고 원래 위치로 되돌아 가지 않도록 클릭했을 때. 내가 이해하지 못하는 것은 두 가지입니다. "if (!$(this)
"코드의 일부분과 어떻게 링크를 찾을 수 있습니까? 정말 고마워!누군가이 코드를 설명해 주시겠습니까?
$(function() {
$('#secondary_content_what_we_do li a').hover(function() {
if (!$(this).hasClass("current")) {
$(this).stop().animate({
"paddingLeft": "10px"
}, 400).addClass('column_hover');
}
}, function() {
if (!$(this).hasClass("current")) {
$(this).stop().animate({
"paddingLeft": "0px"
}, 'slow').removeClass('column_hover');
}
});
$('#secondary_content_what_we_do a').click(function() {
$('a').removeClass('column_active').removeClass("current");
$(this).addClass('column_active').addClass("current");
$('#secondary_content_what_we_do li a').trigger('mouseleave');
var url = $(this).attr('href');
$('#loading_content').hide().load(url).fadeIn(1000);
return false;
});
})
업데이트 몇 가지 이유로 나는 주석을 쓸 수 없습니다. 지금은 이해하지만, 내 CSS에 클래스가 없으므로 그 라인이 어떻게 도움이되는지 잘 모릅니다.
클릭하면 '현재'클래스가'anchor'에 추가됩니다 :'$ (this) .addClass ('column_active'). addClass ("current");'. 클래스에 대한 CSS 규칙을 선언하지 않았다면 상관 없습니다. jQuery는 요소의 상태를 식별하고 추적하는 데 CSS 규칙을 사용하고 있습니다. 따라서 요소 위로 마우스를 가져 가면 코드는 마우스로 가리킨 요소가 클릭 한 마지막 요소인지 확인하고 그에 따라 작동합니다. – fearofawhackplanet