/*============== * index visual ===============*/ var bannerSize; var $bannerItem, paging; var currnetIndex, tId; var done, currentBanner, nextBanner; var playStatus = 'play', btnStatus = 'pause'; $(function(){ addPaging(); init(); setPosition(); startMove(); $('.visual_container>.left_btn>a').on('click', function(e){ e.preventDefault(); if(!done) return; clearInterval(tId); setMoveRight(); if(playStatus == 'play'){ clearInterval(tId); startMove(); } }); $('.visual_container>.right_btn>a').on('click', function(e){ e.preventDefault(); if(!done) return; clearInterval(tId); setMoveLeft(); if(playStatus == 'play'){ clearInterval(tId); startMove(); } }); $('.paging>div>a').on('click', function(e){ e.preventDefault(); clickIndex = $('.paging>div>a').index(this); var indexGap = clickIndex - currentIndex; if( done == false || (clickIndex == currentIndex) ) return; clearInterval(tId); if(indexGap>0){ if( Math.abs(indexGap) == (bannerSize-1) ) moveRight(clickIndex); else moveLeft(clickIndex); } else if(indexGap<0){ if( Math.abs(indexGap) == (bannerSize-1) ) moveLeft(clickIndex); else moveRight(clickIndex); } else if(clickIndex < currentIndex) moveRight(clickIndex); if(playStatus == 'play'){ clearInterval(tId); startMove(); } }); $('.play_stop>a').on('click', function(e){ e.preventDefault(); if(btnStatus == 'pause'){ $(this).addClass('play'); $(this).attr('title', 'Àç»ý'); $(this).text('Àç»ý¹öÆ°'); btnStatus = 'play'; clearInterval(tId); } else if(btnStatus == 'play'){ $(this).removeClass('play'); $(this).attr('title', 'Á¤Áö'); $(this).text('Á¤Áö¹öÆ°'); btnStatus = 'pause'; clearInterval(tId); startMove(); } }); }); function addPaging(){ bannerSize = $('.visual_banner div').size(); if(bannerSize <= 1){ $('.control_btn').remove(); $('.left_btn').remove(); $('.right_btn').remove(); return; } for(var i=0;ipage' + (i+1) + ''); } var playSize = $('.play_stop').width(); $('.control_btn').css({ width:24*bannerSize + (playSize), left:'50%', 'margin-left':-1 * ( $('.control_btn').width()/2 ) }); } function init(){ $bannerItem = $('.visual_banner div'); $paging = $('.paging>div>a'); currentIndex = 0; tId = 0; } function setPosition(){ $bannerItem.css({left:1900}); $bannerItem.eq(0).css({left:0}); $paging.eq(0).addClass('active'); } function startMove(){ if(bannerSize <= 1) return; tId = setInterval(setMoveLeft, 6000); } function setMoveLeft(){ if(currentIndex + 1 >= bannerSize) moveLeft(0); else moveLeft(currentIndex+1); } function setMoveRight(){ if(currentIndex <= 0) moveRight(bannerSize-1); else moveRight(currentIndex-1); } function moveLeft(index){ done = false; $currentBanner = $bannerItem.eq(currentIndex); $nextBanner = $bannerItem.eq(index); $currentBanner.stop().animate({left:-1900}, 1200, 'easeInOutQuint'); $nextBanner.css({left:1900}); $nextBanner.stop().animate({left:0}, 1200, 'easeInOutQuint'); $paging.removeClass('active'); $paging.eq(index).addClass('active'); currentIndex = index; setTimeout(function(){done = true;}, 1200); } function moveRight(index){ done = false; $currentBanner = $bannerItem.eq(currentIndex); $nextBanner = $bannerItem.eq(index); $currentBanner.stop().animate({left:1900}, 1200, 'easeInOutQuint'); $nextBanner.css({left:-1900}); $nextBanner.stop().animate({left:0}, 1200, 'easeInOutQuint'); $paging.removeClass('active'); $paging.eq(index).addClass('active'); currentIndex = index; setTimeout(function(){done = true;}, 1200); } /*============= * index Today ==============*/ var $todaySelect, selectTodaySize, todayCurrent; var doneToday; var tIdToday; $(function(){ initToday(0); // today tab $('.today_section>a').on('click', function(e){ e.preventDefault(); $('.today_section>a').removeClass('active'); $(this).addClass('active'); var selectToday = $('.today_section>a').index(this); $('.today_section>div').hide(); $('.today_section>div').eq(selectToday).show(); initToday(selectToday); }) //arrow click $('.prev_btn').on('click', function(e){ e.preventDefault(); if(doneToday == false) return; clearInterval(tIdToday); setTodayRight(); setTimeout(startMoveToday, 1000); }); $('.next_btn').on('click', function(e){ e.preventDefault(); if(doneToday == false) return; clearInterval(tIdToday); setTodayLeft(); setTimeout(startMoveToday, 1000); }); }); function initToday(selectToday){ if(selectToday == 0){ $todaySelect = $('.perform_article'); } else /*{ $todaySelect = $('.shooting_article'); }*/ selectTodaySize = $todaySelect.size(); todayCurrent = 1; setToday(); startMoveToday(); } function setToday(){ //$todaySelect.css({left:310}); //$todaySelect.eq(0).css({left:0}); $todaySelect.css({display:'none'}); $todaySelect.eq(0).css({display:'block'}); } function startMoveToday(){ clearInterval(tIdToday); tIdToday = setInterval(setTodayLeft, 6000); } function setTodayLeft(){ if(todayCurrent + 1 >= selectTodaySize){ moveTodayLeft(0); } else { moveTodayLeft(todayCurrent+1); } } function setTodayRight(){ if(todayCurrent <= 0){ moveTodayRight(selectTodaySize-1); } else { moveTodayRight(todayCurrent-1); } } function moveTodayLeft(index){ doneToday = false; //console.log('in'); $currentPerform = $todaySelect.eq(todayCurrent); $nextPerform = $todaySelect.eq(index); //$currentPerform.stop().animate({left:-310}, 1000, 'easeInOutQuint'); $currentPerform.fadeOut(1000); //$nextPerform.css({left:310}); //$nextPerform.stop().animate({left:0}, 1000, 'easeInOutQuint'); $nextPerform.fadeIn(1000); todayCurrent = index; setTimeout(function(){doneToday = true;}, 1000); } function moveTodayRight(index){ doneToday = false; $currentPerform = $todaySelect.eq(todayCurrent); $nextPerform = $todaySelect.eq(index); //$currentPerform.stop().animate({left:310}, 1000, 'easeInOutQuint'); $currentPerform.fadeOut(1000); //$nextPerform.css({left:-310}); //$nextPerform.stop().animate({left:0}, 1000, 'easeInOutQuint'); $nextPerform.fadeIn(1000); todayCurrent = index; setTimeout(function(){doneToday = true;}, 1000); }