Tab 버튼을 선택했을 때,선택한 버튼 이미지 관련해서 질문드립니다.
본문
탭 페이지에서 1번 탭의 버튼을 누르면 버튼1의 이미지를, 나머지 탭의 버튼들의 이미지는 버튼2로,
2번 탭의 버튼을 누르면 2번 탭의 버튼이 버튼1의 이미지를, 나머지 탭 버튼의 이미지는 버튼1로 하는 작업을
하려고 합니다.
위와 같이, 단일 탭 버튼에 관해 처리하는 방법은 알겠는데
나머지 탭들에 관해 처리하는 방법은 알 길이 없어서 이렇게 글을 올리게 되었습니다.
다른 분들의 조언 부탁드립니다.
2번 탭의 버튼을 누르면 2번 탭의 버튼이 버튼1의 이미지를, 나머지 탭 버튼의 이미지는 버튼1로 하는 작업을
하려고 합니다.
$('.visual_tab > ul > li > img').each(function(idx) {
var aSrc = $(this).attr('src').replace('_on.png', '_off.png');
$(this).attr('src', aSrc);
$(this).click(function() {
var sSrc = $(this).attr('src');
if(sSrc.indexOf('_on')>-1){
$(this).prop('src',sSrc.replace('_on','_off'))
}
else{
$(this).prop('src',sSrc.replace('_off','_on'))
}
});
});
위와 같이, 단일 탭 버튼에 관해 처리하는 방법은 알겠는데
나머지 탭들에 관해 처리하는 방법은 알 길이 없어서 이렇게 글을 올리게 되었습니다.
다른 분들의 조언 부탁드립니다.
$(document).ready(function() {
/************************
@ visual tab 마우스 이벤트 등록
************************/
$('.visual_tab ul > li').bind('click mouseenter mouseleave',function(event){
if(event.type == 'mouseenter'){
//마우스 오버
visualOver($(this));
}else if(event.type == 'mouseleave'){
//마우스 아웃
visualOut($(this));
}else{
//마우스 클릭
if(_cur != $(this).index()){
_prev = _cur;
_cur = $(this).index();
visual_change($(this).index());
}
}
});
/************************
@ visual 초기화
************************/
visual_len = $('.visual_obj_group > div').length;
visual_init();
visualTimer = setInterval(autoTimer,_time);
$('.visual_content').bind('mouseenter mouseleave',function(event){
if(event.type == 'mouseenter'){
clearInterval(visualTimer)
// console.log('enter');
}else{
visualTimer = setInterval(autoTimer,_time);
// console.log('leave');
}
});
$('.visual_tab > ul > li > img').each(function(idx) {
var aSrc = $(this).attr('src').replace('_on.png', '_off.png');
$(this).attr('src', aSrc);
$(this).click(function() {
var sSrc = $(this).attr('src');
/* alert($(this).attr('src')); */
/* var sSrc = $(this).attr('src').replace('_off.png', '_on.png'); */
/* $(this).attr('src', sSrc); */
if(sSrc.indexOf('_on')>-1){
$(this).prop('src',sSrc.replace('_on','_off'))
}
else{
$(this).prop('src',sSrc.replace('_off','_on'))
}
});
});
});
답변 3
$('.visual_tab ul li').click(function(){
$('.visual_tab ul li > img').each(function(){
$(this).attr("src",$(this).attr("src").replace("on","off"));
});
$(this).find('img').attr("src",$(this).find('img').attr("src").replace("off","on"));
이렇게 하심 되지 않을까요?
아...제가 잘못이해한듯...
많은 도움이 되었습니다. 감사합니다.
답변을 작성하시기 전에 로그인 해주세요.