var pages = [ { //page1 'upIn': ['.logo|on|add', '.circle|on|add', ['.circle-icon|on|add','.icon|on|add'], '.slogan|on|add', '.car-run|on|add|200', '.cdj|on|add|200', '.bmw|on|add|200', '.bm320|on|add'], 'upOut': ['.circle-icon|next|add', '.slogan|next|add|200', '.cdj|on|remove|200', '.bmw|on|remove|200', '.bm320|on|remove', '.car-run|next|add'], 'downIn': ['.car-run|next|remove|100', '.bm320|on|add|100', '.bmw|on|add|100', '.cdj|on|add|100', '.slogan|next|remove', '.circle-icon|next|remove'], 'downOut': [] }, { //page2 'upIn': [ '.niu-ren|on|add', 'body|zoom-out|add', '.mail-icon|on|add', '.words|on|add', '.money|on|add', 'body|zoom-out|add' ], 'upOut': ['.niu-ren|next|add', '.mail-icon|next|add', '.words|next|add'], 'downIn': ['.words|next|remove', '.mail-icon|next|remove', '.niu-ren|next|remove'], 'downOut': ['.words|on|remove', '.mail-icon|on|remove', '.niu-ren|on|remove'] }, { //page3 'upIn': ['.p3-title|on|add', '.recommend|on|add|100', '.recommend-name|on|add|100', '.recommend-tel|on|add|100', '.recommend-mail|on|add|100', '.be-recommend|on|add|100', '.be-recommend-name|on|add|100', '.be-recommend-job|on|add|100', '.be-recommend-resume|on|add|100'], 'upOut': ['.p3-title|next|add|200', '.recommend|next|add|200', ['.recommend-name|next|add|200', '.recommend-tel|next|add|200', '.recommend-mail|next|add|200'], '.be-recommend|next|add|200', ['.be-recommend-name|next|add|200', '.be-recommend-job|next|add|200', '.be-recommend-resume|next|add|200']], 'downIn': ['.be-recommend-resume|next|remove|200', '.be-recommend-job|next|remove|200', '.be-recommend-name|next|remove|200', '.be-recommend|next|remove|200', '.recommend-mail|next|remove|200', '.recommend-tel|next|remove|200', '.recommend-name|next|remove|200', '.recommend|next|remove|200', '.p3-title|next|remove|200'], 'downOut': ['.be-recommend-resume|on|remove|200', '.be-recommend-job|on|remove|200', '.be-recommend-name|on|remove|200', '.be-recommend|on|remove|200', '.recommend-mail|on|remove|200', '.recommend-tel|on|remove|200', '.recommend-name|on|remove|200', '.recommend|on|remove|200', '.p3-title|on|remove|200'] }, { //page4 'upIn': ['.p4-title|on|add', '.java|on|add|100', '.android|on|add|100', '.ios|on|add|100', '.view-design|on|add|100', '.marketing|on|add|100', '.product|on|add|100', '.query-btn|on|add', '.email|on|add'], 'upOut': [], 'downIn': [], 'downOut': ['.email|on|remove|100', '.query-btn|on|remove|100', '.product|on|remove|100', '.marketing|on|remove|100', '.view-design|on|remove|100', '.ios|on|remove|100', '.android|on|remove|100', '.java|on|remove|100', '.p4-title|on|remove'] } ]; /** * css动画就是添加和删除class * @param information * @param container */ function handleClass(information, container){ var infos = information.split('|'); //如果元素不在该page中,全documen查找 var target = container.find(infos[0]); if(target.length == 0){ infos[2] == 'add' ? $(infos[0]).addClass(infos[1]) : $(infos[0]).removeClass(infos[1]) ; } else { infos[2] == 'add' ? target.addClass(infos[1]) : target.removeClass(infos[1]) ; } } var prevTimer; /** * 显示动画 * @param container page容器 * @param aniArr 动画信息数组 * @param index 递归标记 */ function showAnimation(container, aniArr, index, endCall){ clearTimeout(prevTimer); if(index >= aniArr.length){ //递归结束条件 endCall = endCall || function(){}; endCall(); return; } var information = aniArr[index]; var tmpl; //标记自定义时间,数组中的默认第一个元素 if( typeof information == 'string'){ handleClass(information, container); tmpl = information.split('|')[3]; } else { //infos是数组 for(var j= 0,jLen=information.length; j<jLen; j++){ handleClass(information[j], container); } tmpl = information.length > 0 ? information[0].split('|')[3] : undefined; } prevTimer = setTimeout(function(){ showAnimation(container, aniArr, ++index, endCall); }, !!tmpl&&tmpl.trim().length>0 ? parseInt(tmpl) : 500); //没有自定义时间 } /** * 初次载入动画 */ showAnimation($('.page1'), pages[0]['upIn'], 0);
|