function rolling_image(id) { var this_id = $(id), stop_ani = false, _time = null; var curr_idx = 0, next_idx = 0, pc_on_indc = 0, max_idx = 0, bPage2, change_time=5000, speed=500; var image = this_id.find(".visual_img"); function anim() { if(!stop_ani) { _stop(); image.eq(curr_idx).fadeOut(300,function() { image.eq(next_idx).fadeIn(300); }); bPage2 = (curr_idx < 8) ? false : true; set_indicate(); _start(); } } function set_indicate() { if(this_indicator.length > 0) { if(!bPage2) { this_indicator.eq(0).find("a[rel='"+(curr_idx+1)+"']").parent().removeClass("li_on"); this_indicator.eq(0).find("a[rel='"+(curr_idx+1)+"']").parent().addClass("li_off"); if(curr_idx == 7) { this_indicator.eq(1).find("a[rel='"+(next_idx+1)+"']").parent().removeClass("li_off"); this_indicator.eq(1).find("a[rel='"+(next_idx+1)+"']").parent().addClass("li_on"); } else { this_indicator.eq(0).find("a[rel='"+(next_idx+1)+"']").parent().removeClass("li_off"); this_indicator.eq(0).find("a[rel='"+(next_idx+1)+"']").parent().addClass("li_on"); } } else { this_indicator.eq(1).find("a[rel='"+(curr_idx+1)+"']").parent().removeClass("li_on"); this_indicator.eq(1).find("a[rel='"+(curr_idx+1)+"']").parent().addClass("li_off"); if(curr_idx == max_idx) { this_indicator.eq(0).find("a[rel='"+(next_idx+1)+"']").parent().removeClass("li_off"); this_indicator.eq(0).find("a[rel='"+(next_idx+1)+"']").parent().addClass("li_on"); } else { this_indicator.eq(1).find("a[rel='"+(next_idx+1)+"']").parent().removeClass("li_off"); this_indicator.eq(1).find("a[rel='"+(next_idx+1)+"']").parent().addClass("li_on"); } } } } function goto_next(direction) { if(!stop_ani){ if(direction == "prev") { //curr_idx = ((curr_idx - 1) == -1)? max_idx : curr_idx; next_idx = curr_idx - 1; next_idx = (curr_idx == 0)? max_idx : next_idx; } else { //curr_idx = ((curr_idx + 1) > max_idx)? 0 : curr_idx; next_idx = curr_idx + 1; next_idx = (curr_idx == max_idx)? 0 : next_idx; } anim(); curr_idx = next_idx; } } function goto_next2(direction) { if(direction == "prev") { aniPrev(); } else { aniNext(); } } function aniPrev() { var width = image.eq(curr_idx).find("dl").outerWidth(); var size = image.eq(curr_idx).find("dl").size(); var num = 1; var total = num * width; if(size > 1){ //image.eq(curr_idx).removeClass('prev_check'); image.eq(curr_idx).find('div').first().stop(true).animate({ 'left':"-="+total },speed,'easeOutQuint',function(){ /*$('#rollingImg div.rollingImg dl:first-child').clone().appendTo('#rollingImg div.rollingImg').end().remove(); */ var first = image.eq(curr_idx).find('div').first().find('dl:first-child').clone(); image.eq(curr_idx).find('div').first().find('dl:first-child').remove(); image.eq(curr_idx).find('div').first().append(first); image.eq(curr_idx).find('div').first().css('left',0); //image.eq(curr_idx).addClass('prev_check'); }); } } function aniNext() { var width = image.eq(curr_idx).find("dl").outerWidth(); var size = image.eq(curr_idx).find("dl").size(); var num = 1; var total = num * width; if(size > 1) { //if(image.eq(curr_idx).hasClass('next_check')){ image.eq(curr_idx).find('div').first().css('left','-'+total+'px'); /*$('#rollingImg div.rollingImg dl:last-child').clone().prependTo('#rollingImg div.rollingImg').end().remove(); */ var last = image.eq(curr_idx).find('div').first().find('dl:last-child').clone(); image.eq(curr_idx).find('div').first().find('dl:last-child').remove(); image.eq(curr_idx).find('div').first().prepend(last); image.eq(curr_idx).find('div').first().stop(true).animate({ 'left':"+="+total },speed,'easeOutQuint',function(){ //image.eq(curr_idx).addClass('next_check'); }); //} } } function goto_page(idx) { if(!stop_ani) { next_idx = idx; anim(); curr_idx = next_idx; } } function _start() { _time = setInterval(function () { goto_next("next"); }, 5000); stop_ani = false; } function _stop() { clearInterval(_time); stop_ani = true; } max_idx = image.length - 1; var this_cntl = (this_id.find(".visual_img_cntl").length > 0)? this_id.find(".visual_img_cntl") : this_id.parent().find(".visual_img_cntl"); this_cntl.on('click','a',function(e) { e.preventDefault(); var direction = $(this).attr('data-direction'); if(direction.indexOf("pause") != -1) { $(this).hide(); $(this).parent().find(".play").show(); _stop(); } else if(direction.indexOf("play") != -1) { $(this).hide(); $(this).parent().find(".pause").show(); _start(); } else { goto_next2(direction); } }); var this_indicator = (this_id.find(".visual_img_indicator").length > 0)? this_id.find(".visual_img_indicator") : this_id.parent().find(".visual_img_indicator"); this_indicator.on('click','a',function(e) { e.preventDefault(); if($(window).width() <= 640) { location.href = $(this).attr('url'); } else { var idx = $(this).attr('rel'); if(!stop_ani){ goto_page(idx-1); } } }); this_indicator.on('mouseover','li',function() { if($(window).width() <= 640) { this_indicator.find('li').removeClass('li_on'); this_indicator.find('li').removeClass('li_off'); this_indicator.find('li').addClass('li_off'); $(this).removeClass('li_off'); $(this).addClass('li_on'); } }); image.bind('mouseover',function() { _stop(); }); image.bind('mouseleave',function() { _start(); }); /*image.bind('mouseover',function(){ _stop(); }); this_cntl.bind('mouseover',function(){ _stop(); }); image.bind('mouseleave',function(){ image.eq(curr_idx).hide(); _start(); }); this_cntl.bind('mouseleave',function(){ image.eq(curr_idx).hide(); _start(); });*/ $(window).resize(function() { if($(window).width() <= 640) { _stop(); } else { if(stop_ani){ this_indicator.find('li').removeClass('li_on'); this_indicator.find('li').removeClass('li_off'); this_indicator.find('li').addClass('li_off'); _start(); } } }); if($(window).width() > 640) { _start(); } } function rolling_image2(id) { var stop_ani = false, _time = null, this_id = $(id); var curr_idx = 0, next_idx = 0, max_idx = 0, end_cate = 12, change_time=5000, speed=500; var image = this_id.find(".visual_img"); function anim() { if(!stop_ani){ _stop(); image.eq(curr_idx).fadeOut(300,function(){ image.eq(next_idx).fadeIn(300); }); set_indicate(); _start(); } } function set_indicate() { if(this_indicator.length > 0){ this_indicator.find("a[rel='"+(curr_idx+1)+"']").parent().removeClass("li_on"); this_indicator.find("a[rel='"+(curr_idx+1)+"']").parent().addClass("li_off"); this_indicator.find("a[rel='"+(next_idx+1)+"']").parent().removeClass("li_off"); this_indicator.find("a[rel='"+(next_idx+1)+"']").parent().addClass("li_on"); } } function goto_next(direction) { if(!stop_ani){ if(direction == "prev"){ next_idx = curr_idx - 1; next_idx = (curr_idx == 0)? max_idx : next_idx; } else { next_idx = curr_idx + 1; next_idx = (curr_idx == max_idx)? 0 : next_idx; } anim(); curr_idx = next_idx; } } function goto_next2(direction) { if(direction == "prev") { aniPrev(); } else { aniNext(); } } function aniPrev() { var width = image.eq(curr_idx).find("dl").outerWidth(); var size = image.eq(curr_idx).find("dl").size(); var num = 1; var total = num * width; if(size > 1){ //image.eq(curr_idx).removeClass('prev_check'); image.eq(curr_idx).find('div').first().stop(true).animate({ 'left':"-="+total },speed,'easeOutQuint',function(){ /*$('#rollingImg div.rollingImg dl:first-child').clone().appendTo('#rollingImg div.rollingImg').end().remove(); */ var first = image.eq(curr_idx).find('div').first().find('dl:first-child').clone(); image.eq(curr_idx).find('div').first().find('dl:first-child').remove(); image.eq(curr_idx).find('div').first().append(first); image.eq(curr_idx).find('div').first().css('left',0); //image.eq(curr_idx).addClass('prev_check'); }); } } function aniNext() { var width = image.eq(curr_idx).find("dl").outerWidth(); var size = image.eq(curr_idx).find("dl").size(); var num = 1; var total = num * width; if(size > 1){ //if(image.eq(curr_idx).hasClass('next_check')){ image.eq(curr_idx).find('div').first().css('left','-'+total+'px'); /*$('#rollingImg div.rollingImg dl:last-child').clone().prependTo('#rollingImg div.rollingImg').end().remove(); */ var last = image.eq(curr_idx).find('div').first().find('dl:last-child').clone(); image.eq(curr_idx).find('div').first().find('dl:last-child').remove(); image.eq(curr_idx).find('div').first().prepend(last); image.eq(curr_idx).find('div').first().stop(true).animate({ 'left':"+="+total },speed,'easeOutQuint',function(){ //image.eq(curr_idx).addClass('next_check'); }); //} } } function goto_page(idx) { if(!stop_ani){ next_idx = idx; anim(); curr_idx = next_idx; } } function _start() { _time = setInterval(function () { goto_next("next"); }, 5000); stop_ani = false; } function _stop() { clearInterval(_time); stop_ani = true; } max_idx = image.length - 1; var this_cntl = (this_id.find(".visual_img_cntl").length > 0)? this_id.find(".visual_img_cntl") : this_id.parent().find(".visual_img_cntl"); this_cntl.on('click','a',function(e) { e.preventDefault(); var direction = $(this).attr('data-direction'); if(direction.indexOf("pause") != -1) { $(this).hide(); $(this).parent().find(".play").show(); _stop(); } else if(direction.indexOf("play") != -1) { $(this).hide(); $(this).parent().find(".pause").show(); _start(); } else { goto_next2(direction); } }); var this_indicator = (this_id.find(".visual_img_indicator").length > 0)? this_id.find(".visual_img_indicator") : this_id.parent().find(".visual_img_indicator"); this_indicator.on('click','a',function(e){ e.preventDefault(); if($(window).width() <= 640) { location.href = $(this).attr('url'); } else { var idx = $(this).attr('rel'); if(!stop_ani) { goto_page(idx - 1); } } }); this_indicator.on('mouseover', 'li',function(){ if($(window).width() <= 640) { this_indicator.find('li').removeClass('li_on'); this_indicator.find('li').removeClass('li_off'); this_indicator.find('li').addClass('li_off'); $(this).removeClass('li_off'); $(this).addClass('li_on'); } }); image.bind('mouseover',function() { _stop(); }); image.bind('mouseleave',function() { _start(); }); /*image.bind('mouseover',function(){ _stop(); }); this_cntl.bind('mouseover',function(){ _stop(); }); image.bind('mouseleave',function(){ image.eq(curr_idx).hide(); _start(); }); this_cntl.bind('mouseleave',function(){ image.eq(curr_idx).hide(); _start(); });*/ $(window).resize(function() { if($(window).width() <= 640){ _stop(); } else { if(stop_ani) { this_indicator.find('li').removeClass('li_on'); this_indicator.find('li').removeClass('li_off'); this_indicator.find('li').addClass('li_off'); _start(); } } }); if($(window).width() > 640) { _start(); } }