채택완료
Tab 버튼을 선택했을 때, 버튼들 이미지 변경하는 것 관련해서 질문드립니다.
<div class="visual_tab">
<ul>
<li><img src="../images/main/m_visual_btn_01_off.png" class="png active" alt="듀어토닝"/></li>
<li><img src="../images/main/m_visual_btn_02_off.png" class="png" alt="여드름"/></li>
<li><img src="../images/main/m_visual_btn_03_off.png" class="png" alt="안티에이징"/></li>
<li><img src="../images/main/m_visual_btn_04_off.png" class="png" alt="점/검버섯"/></li>
<li><img src="../images/main/m_visual_btn_05_off.png" class="png" alt="힐링케어"/></li>
</ul>
</div>
만약에 이렇게 구성된 페이지에서 탭 버튼에 관해 탭 선택시 이미지를 바꾸는 것에 관련해서 처리를 하는 중인데
//탭 변경에 대한 on, off
$('.visual_tab ul li').click(function(idx){
$('.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"));
});
//탭 버튼 하나에 대한 on, off
$('.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'))
}
});
});
각각 탭에 대한 선택시 on / off까지 기능을 같이 구현하려고 하면 어떻게 수정을 하는게 맞을까요?
이렇게 코딩을 하는데, 탭 버튼 하나에 대한 on, off까지 동시에 먹이려고 하니 쉽지 않네요..ㅎㅎ
다른 분들의 조언 부탁드립니다.
<ul>
<li><img src="../images/main/m_visual_btn_01_off.png" class="png active" alt="듀어토닝"/></li>
<li><img src="../images/main/m_visual_btn_02_off.png" class="png" alt="여드름"/></li>
<li><img src="../images/main/m_visual_btn_03_off.png" class="png" alt="안티에이징"/></li>
<li><img src="../images/main/m_visual_btn_04_off.png" class="png" alt="점/검버섯"/></li>
<li><img src="../images/main/m_visual_btn_05_off.png" class="png" alt="힐링케어"/></li>
</ul>
</div>
만약에 이렇게 구성된 페이지에서 탭 버튼에 관해 탭 선택시 이미지를 바꾸는 것에 관련해서 처리를 하는 중인데
//탭 변경에 대한 on, off
$('.visual_tab ul li').click(function(idx){
$('.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"));
});
//탭 버튼 하나에 대한 on, off
$('.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'))
}
});
});
각각 탭에 대한 선택시 on / off까지 기능을 같이 구현하려고 하면 어떻게 수정을 하는게 맞을까요?
이렇게 코딩을 하는데, 탭 버튼 하나에 대한 on, off까지 동시에 먹이려고 하니 쉽지 않네요..ㅎㅎ
다른 분들의 조언 부탁드립니다.
Copy
$(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');
}
});
//탭 버튼 하나에 대한 on, off
$('.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'))
}
});
});
//탭 변경에 대한 on, off
$('.visual_tab ul li').click(function(idx){
$('.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"));
});
});
|
답변 2개 / 댓글 4개
채택된 답변
+20 포인트
2014-06-11 (수) 20:43:24
each 저건 클릭할때 마다 모든 이미지를 변경하게 되는데 좋은 방법이 아닙니다
작동만 되면 되는 것이 아니라 이미지 변경을 최소화 시켜야죠
//탭 버튼 하나에 대한 on, off , //탭 변경에 대한 on, off 싹 지우고 아래처럼 해보세요
var prev=999;
$('.visual_tab ul li').click(function(){
idx = $(this).index('.visual_tab ul li');
img_src= $(this).find('img').attr("src")
if(img_src.indexOf('_off')>-1 ) img_src= img_src.replace('_off','_on');
else img_src= img_src.replace('_on','_off');
$(this).find('img').attr('src', img_src);
if(prev !=999){
img_prev= $('.visual_tab ul li').eq(prev).find('img').attr('src');
if(img_prev.indexOf('_on')>-1 ){
img_prev=img_prev.replace('_on','_off');
$('.btnk').eq(prev).children('img').attr('src', img_prev);
}
}
prev=idx;
});
답변에 대한 댓글 3개
bismute
2014-06-12 (목) 09:35:03
1,2,3,4,5 버튼이 있는데 1버튼을 누른 상태에서 2로 가면 1은 _off 이미지로 2는 _on 이미지로 하는 거까지 여기서 구현되려면 어떻게 해야 될까요...
bismute
2014-06-17 (화) 09:51:22
1버튼이 눌린 상태에서 2버튼을 누르면, 1버튼의 이미지가 off로 바뀌고 2버튼의 이미지가 on으로 바뀌는 건 해도 안 되더라구요....
제가 중간에 코딩을 잘못해서 그런 걸까요?
제가 중간에 코딩을 잘못해서 그런 걸까요?
커네드커네드
2014-06-11 (수) 10:33:18
탭 버튼 하나에 대한 on, off가 무슨 의미인지 모르겠어요...
답변에 대한 댓글 1개
bismute
2014-06-11 (수) 10:34:27
아...제가 애매하게 써놓았군요...탭 버튼을 눌렀을 때 이미지1, 한번 더 누르면 이미지2 이런식으로 이미지가 변경되는 것을 말씀드리는 거였어요
답변을 작성하려면 로그인이 필요합니다.