본문 바로가기

퍼블리싱/HTML | CSS | Javascript

click이벤트에 여러 효과 동시에 주기 :p 초간단!

 

 

A라는 버튼 하나를 click함으로써 어떤 경우에는 무슨 이벤트가 동작되게, 다른 경우에는 무슨 이벤트가 동작되게 하고싶은 경우가 많다. toggle을 사용하면 되긴 하지만.... 여튼 간단하게 if문으로 제어할수 있는 방법!

 

$('.comm li a').on('click' , function(){
//.text() 또는 .html() 로 문구 검사해서 적용
        if($(this).text() == "착용샷 보기 >"){
           $(this).parent().parent().find('img').css('opacity','0');
           $(this).parent().parent().find('.imgh').animate({'opacity':'1'},500);
           $(this).text('원래대로 보기 >');
       }else{
            $(this).parent().parent().find('img').css('opacity','1')
            $(this).parent().parent().find('.imgh').animate({'opacity':'0'},500)
            $(this).text('착용샷 보기 >')
        }
})
 

 

 

이런식으로, 만일 클릭한 대상의 상태가 ~~~하면 ~~하고, ~~~하면 ~~한다 식으로 if문을 사용하면 된다. 조건만 잘 넣으면 될듯 :) 엄청간단하다.

728x90