/** * Created by Jeon on 2018-05-04. */ var visualImg = $('.v_img img'); var vBtnLi = $(".v_btn_li"); var buttonIndex = 0; //기초 세팅 function nextImg() { var previousButtonIndex = buttonIndex; if(buttonIndex == visualImg.length -1) { buttonIndex = 0; } else { buttonIndex ++; } //이전 인덱스 opacity = 0 으로, 올라올 인덱스 opacity = 1로 바꿔준다. visualImg.eq(previousButtonIndex).animate({"opacity":0},1000); visualImg.eq(buttonIndex).animate({"opacity":1},1000); //이전 인덱스 width 12, background = white 현재 인덱스 width 40 back e7302a vBtnLi.eq(previousButtonIndex).animate({"width":12+"px"},1000); vBtnLi.eq(buttonIndex).animate({"width":40+"px"},1000) vBtnLi.eq(previousButtonIndex).css({"background":"#FFF"}); vBtnLi.eq(buttonIndex).css({"background":"#e7302a"}) vBtnLi.eq(buttonIndex).addClass("v_btn_on"); vBtnLi.eq(previousButtonIndex).removeClass("v_btn_on"); } vBtnLi.click(function() { if(buttonIndex != vBtnLi.index(this)) { var previousButtonIndex = buttonIndex; buttonIndex = vBtnLi.index(this); console.log("now Image Index : " + buttonIndex); console.log("now button Index : " + buttonIndex); //이전 인덱스 opacity = 0 으로, 올라올 인덱스 opacity = 1로 바꿔준다. visualImg.eq(previousButtonIndex).animate({"opacity":0},1000); visualImg.eq(buttonIndex).animate({"opacity":1},1000); //이전 인덱스 width 12, background = white 현재 인덱스 width 40 back e7302a vBtnLi.eq(previousButtonIndex).animate({"width":12+"px"},1000); vBtnLi.eq(buttonIndex).animate({"width":40+"px"},1000); vBtnLi.eq(previousButtonIndex).css({"background":"#FFF"}); vBtnLi.eq(buttonIndex).css({"background":"#e7302a"}); vBtnLi.eq(buttonIndex).addClass("v_btn_on"); vBtnLi.eq(previousButtonIndex).removeClass("v_btn_on"); clearInterval(autoSlider); autoSlider = setInterval(function() { nextImg(); },4000); } }); var autoSlider = setInterval(function() { nextImg(); },4000); //e7302a ,40*12 12*12