(function() { var support = { animations : modernizr.cssanimations }, animendeventnames = { 'webkitanimation' : 'webkitanimationend', 'oanimation' : 'oanimationend', 'msanimation' : 'msanimationend', 'animation' : 'animationend' }, // animation end event name animendeventname = animendeventnames[ modernizr.prefixed( 'animation' ) ], component = null,//容器 items = null,//图片项 numclick = document.queryselector('.numchoose'),//点击数字切换按钮块 piccurrent = 0,//当前点击的数字 picclick = false,//是否点击数字切换事件 current = 0,//当前图片数字记录 txt = document.queryselector( '.itemtxt' ),//当前图片对应文字块 itemscount = null, navnext = document.queryselectorall( '.next' ), navprev = document.queryselectorall( '.prev' ), isanimating = false, tpage = null; var loop;//自动轮播 function move(){ if(numclick!=null){ component = $( '.component' )[0];//容器 items = component.queryselector( 'ul.itemwrap' ).children;//图片项 itemscount = items.length; tpage =$(component.queryselector('.tpage')); current = parseint(tpage.attr('data-num')); console.log(current); navigate( 'next' ); } } function reinit(_this,dir) { component = _this.parents( '.component' )[0],//容器 items = component.queryselector( 'ul.itemwrap' ).children,//图片项 numclick = component.queryselector('.numchoose'),//点击数字切换按钮块 itemscount = items.length, tpage =$(component.queryselector('.tpage')), current = parseint(tpage.attr('data-num')); navigate( dir ); } function init() { for(var i=0;i 0 ? current - 1 : itemscount - 1; } tpage.text(current+1).attr('data-num',current); if(picclick){ current = piccurrent; } if(numclick!=null){ classie.addclass(numclick.children[current],'active'); } var nextitem = items[ current ]; var onendanimationcurrentitem = function() { this.removeeventlistener( animendeventname, onendanimationcurrentitem ); classie.removeclass( this, 'current' ); classie.removeclass( this, dir === 'next' ? 'navoutnext' : 'navoutprev' ); ++cntanims; if( cntanims === 2 ) { isanimating = false; } } var onendanimationnextitem = function() { if(txt!=null){ classie.addclass(txt.children[current],'show'); } v=0.005; this.removeeventlistener( animendeventname, onendanimationnextitem ); classie.addclass( this, 'current' ); classie.removeclass( this, dir === 'next' ? 'navinnext' : 'navinprev' ); ++cntanims; if( cntanims === 2 ) { isanimating = false; } } if( support.animations ) { currentitem.addeventlistener( animendeventname, onendanimationcurrentitem ); nextitem.addeventlistener( animendeventname, onendanimationnextitem ); } else { onendanimationcurrentitem(); onendanimationnextitem(); } classie.addclass( currentitem, dir === 'next' ? 'navoutnext' : 'navoutprev' ); classie.addclass( nextitem, dir === 'next' ? 'navinnext' : 'navinprev' ); } init(); })();