// banner var timeout,playend=true,maxwidth=1440,maxheight=340,playwidth=0; function hp_reset(){ $(window).width()>maxwidth ? playwidth=maxwidth : playwidth=$(window).width(); $('.hp_banner').css({width:playwidth, height:maxheight, left:($(window).width()-playwidth)/2}); $('.hp_banner .sl_list div').width(playwidth); $('.hp_banner .sl_list').width($('.hp_banner li').length * playwidth); $('.hp_banner .sl_list').stop(); index = $('.hp_banner .sl_list div').index($('.hp_banner .sl_list .sl_list_on')); $('.hp_banner .sl_list').css({left:-(playwidth * index)}); playend=true; } function hp_ini(){ $('.hp_banner').append('
').find('div').height(maxheight); //$('.hp_banner').append('
'); $('.hp_banner li').each(function(index, element) { var _this = $('.hp_banner .sl_list').append('
').find('div').eq(index).css({backgroundImage:'url('+$(element).find('img').attr('src')+')', height:maxheight}) if($(element).find('a').attr('href')!="" && $(element).find('a').attr('href')!=undefined) _this.append(''); $('.hp_banner .sl_list_dot').append(''); }); $('.hp_banner .sl_list').append('left'); $('.hp_banner .sl_list div').eq(0).addClass('sl_list_on'); //--- arr $('.hp_banner').append(''); $('.hp_banner_prev').css({left:30, top:($('.hp_banner .sl_list').height()-$('.hp_banner_prev').height())/2}); $('.hp_banner_next').css({right:30, top:($('.hp_banner .sl_list').height()-$('.hp_banner_prev').height())/2}); $('.hp_banner').hover( function(){ $('.hp_banner_prev,.hp_banner_next').fadeIn() }, function(){ $('.hp_banner_prev,.hp_banner_next').fadeOut() } ); $('.hp_banner_prev').click(function(e) { $('.hp_banner_dir').text('left'); hp_autoPlay(null); }); $('.hp_banner_next').click(function(e) { $('.hp_banner_dir').text('right'); hp_autoPlay(null); }); //--- dot $('.hp_banner .sl_list_dot').css({left:($(window).width()-800)/2}) $('.hp_banner .sl_list_dot span').click(function(e) { hp_autoPlay($('.hp_banner .sl_list_dot span').index(this)); }); //--- hp_reset(); } function hp_autoPlay(playto){ if(!playend) return false; playend = false; clearTimeout(timeout); index = $('.hp_banner .sl_list div').index($('.hp_banner .sl_list .sl_list_on')); $('.hp_banner .sl_list .sl_list_on').removeClass('sl_list_on'); if($('.hp_banner_dir').text()=='left'){ index++; if(index+1>$('.hp_banner .sl_list div').length) index=0; }else{ index--; if(index<0) index=$('.hp_banner .sl_list div').length-1; } if(playto!=null){ index = playto; } $('.hp_banner .sl_list div').eq(index).addClass('sl_list_on'); $('.hp_banner .sl_list').stop().animate({left:-(playwidth * index)}, 500, function(){ playend=true; }); $('.hp_banner .sl_list_dot span').removeClass('on'); $('.hp_banner .sl_list_dot span').eq(index).addClass('on'); timeout = setTimeout(function(){ hp_autoPlay(null); }, 8000); } //--- function bn_reset(){ $('.bntxt').css({left:$('.wrapper').offset().left}); } bn_reset(); //--- function winonresize(){ hp_reset(); bn_reset(); } $(document).ready(function(){ hp_ini(); hp_autoPlay(0); }); window.onresize = winonresize;