/*xn_ba_js_14_banner*/ //自动播放与时间间隔 var xn_ba_js_14_autoplay = true; var xn_ba_js_14_interval = 5000; /** ** 通过指定不同的数值变幻不同的效果 ** xn_ba_js_14_effect = -1 原地透明渐变切换效果 ** xn_ba_js_14_effect = 0 双按钮双效果切换效果 ** xn_ba_js_14_effect = 1 全屏轮播 **/ var xn_ba_js_14_effect = -1; /** 满屏播放(100%)或具体数值 **/ var bannerw = "100%"; var xn_ba_js_14_nextfunc; var xn_ba_js_14_timer; $(document).ready(function(){ xn_ba_js_14_start(); function banner_oncreate() { $.ajax({url:"banner.txt",data:{key1:1,key2:2},success:initsuccess,error:initerror,datatype:"text"}); } function banner_reload() { window.location.reload(false); } function initsuccess(data) { $(".xn_ba_js_14_container").html(data); xn_ba_js_14_start(); } function initerror(xmlhttprequest, textstatus, errorthrown) { alert("出现异常:"+[errorthrown,textstatus,errorthrown]); } }); var xn_ba_js_14_start = function(){ var maxlen = 0; var index = 0; var prev = 0; var imgw,imgh,sizew,sizeh = 0; var running = false; maxlen = $(".xn_ba_js_14_element").length; imgw = $(".xn_ba_js_14_bigimg").find("img").eq(0).width(); imgh = $(".xn_ba_js_14_bigimg").find("img").eq(0).height(); //按钮相关 var btndata = ""; for(var i=0;i index ? 1 : -1; if(xn_ba_js_14_effect == 1) { //图片轮播效果 if(dir==1) { for(var i=index+1;i<=target;i++) { index = i; nextpage(); } }else if(dir == -1) { for(i=index-1;i>=target;i--) { index = i; prevpage(); } } }else { //原地渐变切换效果 var cur = index; if(dir==1) { cur++; if(cur > maxlen-1)cur = 0; }else { cur--; if(cur < 0)cur = maxlen-1; } index = target; toggle(); } } function skiphandler() { if(xn_ba_js_14_timer) { //重置 clearinterval(xn_ba_js_14_timer); timerrepeat(); } if ($(window.parent.bannerparam).length > 0) { //设置全局索引 window.parent.bannerparam.cur_ba_index = index; } var btn = $(".xn_ba_js_14_btn").find("li"); btn.eq(prev).attr("class","xn_ba_js_14_element_btn"); btn.eq(index).attr("class","xn_ba_js_14_element_btn_on"); var indexpic = $(".xn_ba_js_14_element").eq(index); var prevpic = $(".xn_ba_js_14_element").eq(prev); indexpic.css("visibility","visible"); indexpic.css({visibility:"visible",left:math.round((sizew-imgw)/2)}); } //图片轮转,循环播放 function timerrepeat() { if(!xn_ba_js_14_autoplay)return; xn_ba_js_14_nextfunc = ispause; xn_ba_js_14_timer = setinterval("xn_ba_js_14_nextfunc()",xn_ba_js_14_interval); } function ispause() { //每次跳转前检测判断值 var isrun = true; if(typeof parent.runonce != 'undefined') { isrun = parent.runonce; } if(isrun) { var cur = index; cur++; if(cur > maxlen-1)cur = 0; togglehandler(cur); return false; }else { return true; //暂停 } } function toggle(){ skiphandler(); var indexpic = $(".xn_ba_js_14_element").eq(index); var prevpic = $(".xn_ba_js_14_element").eq(prev); indexpic.stop().css("opacity",0).animate({ opacity:1 },{ duration:700, easing:'easeoutquint', complete:function() { slideend(prevpic); } }); //ie8 文字透明度无效 indexpic.find(".xn_ba_js_14_zt").stop().animate({ opacity:1 },{ duration:700 }); prevpic.find(".xn_ba_js_14_zt").stop().animate({ opacity:0 },{ duration:700 }); prevpic.stop().animate({ opacity:0 },{ duration:700, easing:'easeoutquint' }); prev = index; } function arrowonclick(dir) { if(xn_ba_js_14_effect == 0 || xn_ba_js_14_effect == 1) { //图片轮播效果 if(dir==1) { index++; if(index>=maxlen)index = 0; nextpage(); }else if(dir == -1) { index--; if(index<0)index = maxlen - 1; prevpage(); } }else { //原地渐变切换效果 if(dir==1) { index++; if(index > maxlen-1)index = 0; }else { index--; if(index < 0)index = maxlen-1; } toggle(); } } function prevpage(){ skiphandler(); $(".xn_ba_js_14_element").eq(index).find(".xn_ba_js_14_zt").stop().css("opacity",1); for(var i = 0 ; i < maxlen ; i++){ var _pos = math.round(imgw*(i-index)+$(window).width()/2-imgw/2); var _opa = 1; if(_pos < -imgw){ _pos += maxlen*imgw }else if(_pos > $(window).width()+imgw){ _pos -= maxlen*imgw } $(".xn_ba_js_14_element").eq(i) .stop() .css({ left:_pos-imgw }) .animate({ left:_pos, opacity:_opa },{ duration:700 , easing:'easeoutquint', queue:false }) } prev = index; } function nextpage() { skiphandler(); $(".xn_ba_js_14_element").eq(index).find(".xn_ba_js_14_zt").stop().css("opacity",1); for(var i = 0 ; i < maxlen ; i++){ var _pos = math.round(imgw*(i-index)+sizew/2-imgw/2); var _opa = 1; if(_pos > sizew){ _pos -= maxlen*imgw }else if(_pos < -imgw*2){ _pos += maxlen*imgw } $(".xn_ba_js_14_element").eq(i) .stop() .css({ left:_pos+imgw }) .animate({ left:_pos, opacity:_opa },{ duration:700 , easing:'easeoutquint' }) } prev = index; } function slideend(element) { var prevpic = $(".xn_ba_js_14_element").eq(prev); element.css("visibility","hidden"); prev = index; } } /*----- easing ------*/ jquery.extend( jquery.easing,{ def: 'easeoutquint', swing: function (x, t, b, c, d) { return jquery.easing[jquery.easing.def](x, t, b, c, d); }, easeoutquint: function (x, t, b, c, d) { return c*((t=t/d-1)*t*t*t*t + 1) + b; } }); /*end_xn_ba_js_14_banner*/