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

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

QA

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

답변 1

본문

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

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

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

 


$(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


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

음 ㅠㅠ 계속 따른 것도 on이 되어있네요 ㅠㅠ


$(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")); // 이미지를 변경
        }
    });
});


답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 21
© SIRSOFT
현재 페이지 제일 처음으로