채택완료

제이쿼리 질문 ㅠ 자신을 제외한 나머지 이미지 변경 ㅠ

클릭을 했을 때 자신을 제외한 나머지 들을 on->off로 바꾸려고 하거든요 ㅠ?

not을 쓰면 될 것 같은데 짱구가 멈췄어요..

어찌될지... 조언 좀 부탁드리겠습니다

 

Copy
$(function() {
////////////////GNB 메뉴 기능/////////////////
//클릭 했을 때 이미지 변경
    $('.nav-link img').on('click', function() {
        $(this).addClass("gnb-hover gnb-click"); // hover 클랙스 붙히기
        $(this).attr("src", $(this).attr("src").replace("_off","_on")); // 이미지 변경
        //자신을 제외한 나머지 부분 on->off로 변경
    });

//마우스오버 했을 때 이미지 변경
    $(".nav-link img").mouseover(function() { //마우스를 올렸을 때
        $(this).attr("src", $(this).attr("src").replace("_off","_on")); // 이미지 변경
    });

//mouse out 했을 때 이미지 변경
    $(".nav-link img").mouseout(function() { // 마우스를 떼었을때
        if(!$(this).hasClass("gnb-hover")){ // gnb-hover가 아니라면
            $(this).attr("src", $(this).attr("src").replace("_on", "_off")); // 이미지를 변경
        }
    });
});
|

답변 1개 / 댓글 2개

채택된 답변
+20 포인트

Copy
$('.nav-link img').not($(this)).attr("src").replace("_on","_off");

답변에 대한 댓글 2개

음 ㅠㅠ 계속 따른 것도 on이 되어있네요 ㅠㅠ
[code]
$(function() {
////////////////GNB 메뉴 기능/////////////////
//클릭 했을 때 이미지 변경
$('.nav-link img').on('click', function() {
$(this).addClass("gnb-hover"); // hover 클랙스 붙히기
$(this).attr("src", $(this).attr("src").replace("_off","_on")); // 이미지 변경
$('.nav-link img').not($(this)).attr("src").replace("_on","_off");//자신을 제외한 나머지 부분 on->off로 변경
});

//마우스오버 했을 때 이미지 변경
$(".nav-link img").mouseover(function() { //마우스를 올렸을 때
$(this).attr("src", $(this).attr("src").replace("_off","_on")); // 이미지 변경
});

//mouse out 했을 때 이미지 변경
$(".nav-link img").mouseout(function() { // 마우스를 떼었을때
if(!$(this).hasClass("gnb-hover")){ // gnb-hover가 아니라면
$(this).attr("src", $(this).attr("src").replace("_on", "_off")); // 이미지를 변경
}
});
});


[/code]
그럼 이렇게 한번..해보셔요
$('.nav-link img').not($(this)).attr("src",$('.nav-link img').not($(this)).attr("src").replace("_on","_off"));

답변을 작성하려면 로그인이 필요합니다.