/** *author:xz *homepage:www.cnhubei.com * */ if(!EJS.Effect){EJS.Effect = {};} /** 场景对象 */ EJS.Effect.ScrollSceneBase = { ATTRIBUTE_MAP : [ {name : "id", alias : "id", type : "string", defaultValue : EJS.IDX.next} ,{name : "domId", alias : "domId", type : "string", defaultValue : null} ,{name : "domWidth", alias : "domWidth", type : "int", defaultValue : null} ,{name : "domHeight", alias : "domHeight", type : "int", defaultValue : null} //运动速度,优生级高于面板属性 ,{name : "speed", alias : "speed", type : "int", defaultValue : null} //间歇时长,优生级高于面板属性 ,{name : "delay", alias : "delay", type : "int", defaultValue : null} //转场效果 ,{name : "effect", alias : "effect", type : "string", defaultValue : "scroll"} //运运类型 ,{name : "transition", alias : "transition", type : "string", defaultValue : null} //运动方向,优生级高于面板属性 ,{name : "direction", alias : "direction", type : "string", defaultValue : null} //场景间的行间距 ,{name : "lineSpacing", alias : "lineSpacing", type : "int", defaultValue : 0} //场景间的列间距 ,{name : "columnSpacing", alias : "columnSpacing", type : "int", defaultValue : 0} ] ,setId : function(_id){ this.id = _id; } ,getId : function(){ return this.id; } ,setDom : function(_dom){ this.dom = _dom; } ,getDom : function(){ return this.dom; } ,setDomId : function(_domId){ this.domId = _domId; EJS.DomHelper.setAttribute(this.dom, {id : _domId}); } ,getDomId : function(){ return this.domId; } ,setDomWidth : function(_domWidth){ this.domWidth = parseInt(_domWidth); } ,getDomWidth : function(){ return isNaN(parseInt(this.domWidth)) ? -1 : this.domWidth; } ,setDomHeight : function(_domHeight){ this.domHeight = parseInt(_domHeight); } ,getDomHeight : function(){ return isNaN(parseInt(this.domHeight)) ? -1 : this.domHeight; } ,setDomLeft : function(_domLeft){ this.domLeft = _domLeft; EJS.DomHelper.setStyle(this.dom, {left : _domLeft + "px"}); } ,getDomLeft : function(){ return this.domLeft || 0; } ,setDomTop : function(_domTop){ this.domTop = _domTop; EJS.DomHelper.setStyle(this.dom, {top : _domTop + "px"}); } ,getDomTop : function(){ return this.domTop || 0; } ,setSpeed : function(_speed){ this.speed = parseInt(_speed); } ,getSpeed : function(){ return isNaN(parseInt(this.speed)) ? 0 : this.speed; } ,setDelay : function(_delay){ this.delay = parseInt(_delay); } ,getDelay : function(){ return isNaN(parseInt(this.delay)) ? 0 : this.delay; } //设置场景的转场效果 ,setEffect : function(_effect){ this.effect = _effect; } ,getEffect : function(){ return this.effect; } ,setLineSpacing : function(_lineSpaceing){ this.lineSpaceing = _lineSpaceing; } ,getLineSpacing : function(){ return this.lineSpaceing; } ,setColumnSpacing : function(_columnSpacing){ this.columnSpacing = _columnSpacing; } ,getColumnSpacing : function(){ return this.columnSpacing; } //设置场景的运动方向 ,setDirection : function(_direction){ this.direction = _direction; } ,getDirection : function(){ return this.direction; } ,setPosition : function(_type){ EJS.DomHelper.setStyle(this.dom, {position : _type}); //this.dom.style.postion=_type; } ,hide : function(){ EJS.DomHelper.setStyle(this.dom, {display : "none"}); this.ishide = true; } ,display : function(){ EJS.DomHelper.setStyle(this.dom, {display : "block"}); this.ishide = false; } } EJS.Effect.ScrollScene = EJS.ClassHelper.create(); EJS.Effect.ScrollScene.prototype = { initialize : function(_config){ EJS.ClassHelper.setAttributes(this, this.ATTRIBUTE_MAP, _config);//初始化控件属性 } } EJS.ObjectHelper.extend(EJS.Effect.ScrollScene, EJS.Effect.ScrollSceneBase); /** 面板对象 */ EJS.Effect.ScrollPanelBase = { ATTRIBUTE_MAP : [ {name : "domId", alias : "domId", type : "string", defaultValue : null} ,{name : "domWidth", alias : "domWidth", type : "int", defaultValue : 500} ,{name : "domHeight", alias : "domHeight", type : "int", defaultValue : 500} //滚动方式分为,连续(continuous),间歇(intermittent) ,{name : "scrollType", alias : "scrollType", type : "string", defaultValue : "continuous"} //是否是自动运行 ,{name : "autoRun", alias : "autoRun", type : "string", defaultValue : false} //开始的第一个动作 ,{name : "firstAction", alias : "firstAction", type : "string", defaultValue : "out"} //命令队列容量 ,{name : "commandQueueMaxSize", alias : "commandQueueMaxSize", type : "int", defaultValue : 5} //控制器上命令元素的的触发事件 ,{name : "triggerEvent", alias : "triggerEvent", type : "string", defaultValue : "click"} ,{name : "tagName", alias : "tagName", type : "string", defaultValue : "div"} ,{name : "startFun", alias : "startFun", type : "object", defaultValue : null} ,{name : "tagName", alias : "endFun", type : "object", defaultValue : null} ] ,setDom : function(_dom){ this.dom = _dom; } ,getDom : function(){ return this.dom; } ,setDomId : function(_domId){ this.domId = _domId; EJS.DomHelper.setAttribute(this.dom, {id : _domId}); } ,getDomId : function(){ return this.domId; } ,setDomWidth : function(_domWidth){ this.domWidth = parseInt(_domWidth); } ,getDomWidth : function(){ return isNaN(parseInt(this.domWidth)) ? -1 : this.domWidth; } ,setDomHeight : function(_domHeight){ this.domHeight = parseInt(_domHeight); } ,getDomHeight : function(){ return isNaN(parseInt(this.domHeight)) ? -1 : this.domHeight; } ,setDomLeft : function(_domLeft){ this.domLeft = _domLeft; EJS.DomHelper.setStyle(this.dom, {left : _domLeft + "px"}); } ,getDomLeft : function(){ return this.domLeft || 0; } ,setDomTop : function(_domTop){ this.domTop = _domTop; EJS.DomHelper.setStyle(this.dom, {top : _domTop + "px"}); } ,getDomTop : function(){ return this.domTop || 0; } ,setScrollType : function(_st){ this.scrollType = _st; } ,getScrollType : function(){ return this.scrollType; } ,setAutoRun : function(_autoRun){ this.autoRun = _autoRun; } ,getAutoRun : function(){ return this.autoRun; } //添加场景 ,addScene : function(_scene){ if(this.sceneList == null){ this.sceneList = new EJS.Util.SortCache(true); } this.sceneList.push({key : "s_"+_scene.getId(), value : _scene}); } //按ID获取场景 ,getSceneById : function(_id){ if(this.sceneList == null) return null; return this.sceneList.getByKey(_id); } //按顺序获取场景 ,getSceneByIndex : function(_index){ if(this.sceneList == null) return null; return this.sceneList.getByIndex(_index); } ,setFirstAction : function(_firstAction){ this.firstAction = _firstAction; } ,getFirstAction : function(){ return this.firstAction; } //命令队列用于存放入场场景,队列中的场景优先级高于面板中场景队列,只到命令队列中的所有场景全部完成出场动作后,面板中的场景队列才开始入场。 ,setCommandQueueMaxSize : function(_size){ this.commandQueueMaxSize = _size; } ,getCommandQueueMaxSize : function(){ return this.commandQueueMaxSize; } //正在运动的场景分为当前场景(准备出场的场景)与预备场景(准备入场的场景),当预备场景完成了入场动作后,即转变成当前场景 //设置场景的ID号为当前场景 ,setCurrentScene : function(_id){ this.currentScene = _id; } //获取当前场景 ,getCurrentScene : function(){ return this.currentScene; } //设置场景的ID号为预备场景 ,setStandby : function(_id){ this.standby = _id; } //获取预备场景 ,getStandby : function(){ return this.standby; } ,setTriggerEvent : function(_eventType){ this.triggerEvent = _eventType; } ,getTriggerEvent : function(){ return this.triggerEvent; } ,run : function(){ this._isActive = false;//设置为静止状态,到这里有两种情况,1:程序刚开始运行,2:转场效果已结果 if(this.getStandby() != null){//将已完成入场动作的准备场景切换成当前场景,做出场景准备 //this.getCurrentScene().hide();//将已完成出场动作的当前场景隐藏 //alert(this.getStandby().getDomHeight()) this.setCurrentScene(this.getStandby()); } if(this.getCurrentScene() != null){//查看当前场景是否存在,只在两种情况下才会存在当前场景,1、控件初始化时就指定了当前场景;2、准备场景完成了入场动作,已被切换成当前场景 this._sceneIndex = this.sceneList.getIndex("s_"+this.getCurrentScene().getId()); } this._sceneIndex = this._sceneIndex == null ? 0 : ++this._sceneIndex; /* if(this._sceneIndex == null){ this._sceneIndex = 0; }else{ this._sceneIndex++; } */ var slen = this.sceneList.size(); if(this._sceneIndex > slen - 1){ this._sceneIndex = this._sceneIndex % slen; } this.setStandby(this.getSceneByIndex(this._sceneIndex));//获取预备场景 this.effect = EJS.FunctionHelper.bind(this, function(){ var commandObj = this._getCommand();//获取命令队列中的命令 var direction = null; var transition = null; var speed = null; if(commandObj){//如果命令队列中有命令 if(this.startFun){//如果配置有开始接入点,则执行 this.startFun(); } if(!isNaN(parseInt(commandObj.command))){ this._sceneIndex = parseInt(commandObj.command); }else{ if(commandObj.command == "pre"){//将前一个场景做为预备场景 if(this._sceneIndex == null){ this._sceneIndex = -1; }else{ this._sceneIndex -= 2; } }else if(commandObj.command == "next"){//将后一个场景做为预备场景 if(this._sceneIndex == null){ this._sceneIndex = 0; } } if(this._sceneIndex < 0){ this._sceneIndex = Math.abs(this.sceneList.size() + this._sceneIndex); } } var slen = this.sceneList.size(); if(this._sceneIndex > slen - 1){ this._sceneIndex = this._sceneIndex % slen; } var standby = this.getSceneByIndex(this._sceneIndex); if(standby.getId() == this.getCurrentScene().getId() && !standby.ishide){return false;}//如果下一个场景与当前场景相同,则不做任何动作 //运动方向 direction = commandObj.direction ? commandObj.direction : null; transition = commandObj.transition ? commandObj.transition : null; speed = !isNaN(parseInt(commandObj.speed)) ? commandObj.speed : null; //alert(this.getSceneByIndex(this._sceneIndex).getId()+","+this.getCurrentScene().getId()) this.setStandby(standby);//获取预备场景 } direction = direction ? direction : this.getStandby().getDirection(); transition = transition ? transition : this.getStandby().getTransition(); speed = !isNaN(parseInt(speed)) ? speed : this.getStandby().getSpeed(); var effectObj; switch(this.getStandby().getEffect()){ case "scroll" : //effectObj = new EJS.Effect.ScrollTransition.tt1(); effectObj = EJS.Effect.ScrollTransition.tt1; break; default : break; } this._isActive = true;//设置为活动状态 //alert("test="+this.getCurrentScene()); effectObj.start(EJS.FunctionHelper.bind(this, function(){ if(this.endFun){this.endFun();}//如果配置了结束接入点,则执行 this._callback(); }), this.getCurrentScene(), this.getStandby(), {"width" : this.getCurrentScene().getDomWidth(), "height" : this.getCurrentScene().getDomHeight(), "direction" : direction, "transition" : transition , "speed" : speed, "lineSpacing" : this.getStandby().getLineSpacing(), "columnSpacing" : this.getStandby().getColumnSpacing()}); }); if(!this._requestInterrupt){//当没有中断请求时,就继续运行 if(this._commandSize() > 0){//如果命令队列中有命令,执行命令不用时间间隔 this.effect(); }else{ if(this.getAutoRun()){//如果为自动播放模式 if(this.getStandby().getDelay() > 0){ this.delayTimer = window.setTimeout(this.effect, this.getStandby().getDelay()); }else{ this.effect(); } } } } } //暂停方法 ,pause : function(){ this._requestInterrupt = true;//请求一个中断信号 //if(!this._isActive){ window.clearTimeout(this.delayTimer); //} } //开始 ,reStart : function(){ this._requestInterrupt = false;//取消中断 if(!this._isActive){//在静止状态时,才会重新触发运行 if(this.effect){ if(this._commandSize() > 0){ this.effect(); }else{ if(this.getAutoRun()){//如果为自动播放模式 if(this.getStandby().getDelay() > 0){ this.delayTimer = window.setTimeout(this.effect, this.getStandby().getDelay()); }else{ this.effect(); } } } }else{ this.run(); } } } ,pre : function(_direction, _transition, _speed){ _direction = _direction ? _direction : this.getStandby().getDirection(); _transition = _transition ? _transition : this.getStandby().getTransition(); _speed = !isNaN(parseInt(_speed)) ? _speed : this.getStandby().getSpeed(); this._addCommandQueue({"command" : "pre", "direction" : _direction, "transition" : _transition, "speed" : _speed}); this.pause(); this.reStart(); } ,next : function(_direction, _transition, _speed){ _direction = _direction ? _direction : this.getStandby().getDirection(); _transition = _transition ? _transition : this.getStandby().getTransition(); _speed = !isNaN(parseInt(_speed)) ? _speed : this.getStandby().getSpeed(); this._addCommandQueue({"command" : "next", "direction" : _direction, "transition" : _transition, "speed" : _speed}); this.pause(); this.reStart(); } ,to : function(_index,_direction, _transition, _speed){ //alert(this.getSceneByIndex(_index).getDirection()); _direction = _direction ? _direction : this.getSceneByIndex(_index).getDirection(); _transition = _transition ? _transition : this.getStandby().getTransition(); _speed = !isNaN(parseInt(_speed)) ? _speed : this.getStandby().getSpeed(); this._addCommandQueue({"command" : _index, "direction" : _direction, "transition" : _transition, "speed" : _speed}); this.pause(); this.reStart(); } //去掉控制器样式、隐藏当前显示的场景,此方法为临时解决方案 //flag:1:修改样式 2:隐藏当前显示的场景,3:同时执行1与2 ,unset : function(flag){ if(this.currentActiveControlDom){ if(flag == 1 || flag == 3){ EJS.CssHelper.modifyName(this.currentActiveControlDom, this.clazzArr[this.currentActiveControlDomIndex][0]);//设置为正常样式 } if(flag == 2 || flag == 3){ this.getCurrentScene().hide(); } } } //private /** 向命令队列中添加下一个命令(pre,next,数字) */ ,_sceneIndex : null//将预备场景的序号设置为空 ,_isRun : false//是否已经开始运行(未用) ,_isActive : false//当前是否在运动,当场景在动时就为true ,_requestInterrupt : false//请求中断 ,_addCommandQueue : function(_com){ //if(this._isActive) return;//当前为活动状态时,禁止添加命令 if(this.commandQueue == null){ this.commandQueue = new EJS.Util.queue(); } if(this.commandQueue.size() < this.getCommandQueueMaxSize()){ this.commandQueue.tIn(_com);//入队 }else{ //var cqlen = this.commandQueue.length; //比较最后面的命令与将要插入的命令时否相同,在队满的情况下,相同的命令不能插入,不相同的命令则将最后一个命令替换为将插入的命令 if(this.commandQueue.last() != _com){ this.commandQueue.tOut();//移除队列最后的一个命令 this.commandQueue.tIn(_com);//入队 } } } //从命令队列中取出最前面的命令 ,_getCommand : function(){ if(this.commandQueue == null){ return null; }else if(!this.commandQueue.isEmpty()){ return this.commandQueue.hOut(); } } //获取命令队列的命令的个数 ,_commandSize : function(){ if(this.commandQueue == null){ return 0; } return this.commandQueue.size(); } } EJS.Effect.ScrollPanel = EJS.ClassHelper.create(); EJS.Effect.ScrollPanel.prototype = { initialize : function(_config){ var setting = { "tagName" : "div" ,"direction" : "up" ,"transition" : "easeOutCubic" ,"follow" : "next" ,"activeItem" : -1 ,"speed" : 1 ,"delay" : 3000 }; EJS.ObjectHelper.extend(_config, setting); EJS.ClassHelper.setAttributes(this, this.ATTRIBUTE_MAP, _config);//初始化控件属性 //是否设置了面板ID if(this.getDomId()){ var dom = EJS.getElement(this.getDomId()); if(!dom) return; //this.effect = null;//转场效果 //回调函数,用于在完成场景转场后,通知面板转场已完成可以进行下一步操作了 this._callback = EJS.FunctionHelper.bind(this, this.run); //设置面板属性 this.setDom(dom); this.setDomWidth(dom.offsetWidth); this.setDomHeight(dom.offsetHeight); if(_config.control){//如果配置了控件器 var controlConfArr = _config.control; //按照控制器的配置参数设置 this.clazzArr = [];//将所有样式放到一个数组中,便于后面的样式切换效果 this.currentActiveControlDom = null; this.currentActiveControlDomIndex = null; for(var i = 0; i < controlConfArr.length; i++){ var cid = controlConfArr[i].domId; if(cid == null){continue;} var cDom = EJS.$(cid); if(cDom == null){continue;} var follow = controlConfArr[i].follow == null ? _config.follow : controlConfArr[i].follow; var triggerEvent = controlConfArr[i].triggerEvent ? controlConfArr[i].triggerEvent : this.getTriggerEvent(); var direction = controlConfArr[i].direction ? controlConfArr[i].direction : null; var transition = controlConfArr[i].transition ? controlConfArr[i].transition : null; var speed = !isNaN(parseInt(controlConfArr[i].speed)) ? controlConfArr[i].speed : null; var _f = function(_a){ //if(this._isActive){return;}//如果当前场景是活动的,则不做任何操作 if(_a[0] == "pre"){ this.pre.apply(this, [_a[1], _a[2], _a[3]]); }else if(_a[0] == "next"){ this.next.apply(this, [_a[1], _a[2], _a[3]]); }else{ this.to.apply(this, [_a[0], _a[1], _a[2], _a[3]]); } var controlDom = _a[4]; //alert(controlDom.outerHTML); var clazz1 = this.clazzArr[this.currentActiveControlDomIndex]; var clazz2 = this.clazzArr[_a[5]]; if(this.currentActiveControlDom && clazz1 && clazz1.length > 1){ EJS.CssHelper.modifyName(this.currentActiveControlDom, clazz1[0]);//设置为正常样式 } if(controlDom && clazz2 && clazz2.length > 1){ EJS.CssHelper.modifyName(controlDom, clazz2[1]);//设置为激活样式 this.currentActiveControlDom = controlDom; this.currentActiveControlDomIndex = _a[5]; } } if(follow == "pre"){ //EJS.EventListener.add(cDom, triggerEvent, EJS.FunctionHelper.bind(this, this.pre, direction, transition, speed)); EJS.EventListener.add(cDom, triggerEvent, EJS.FunctionHelper.bind(this, _f, ["pre", direction, transition, speed, cDom, i])); }else if(follow == "next"){ EJS.EventListener.add(cDom, triggerEvent, EJS.FunctionHelper.bind(this, _f, ["next", direction, transition, speed, cDom, i])); }else if(!isNaN(parseInt(follow))){ //EJS.EventListener.add(cDom, triggerEvent, EJS.FunctionHelper.bind(this, function(_index){this.to(_index);}, parseInt(follow))); EJS.EventListener.add(cDom, triggerEvent, EJS.FunctionHelper.bind(this, _f, [parseInt(follow), direction, transition, speed, cDom, i])); } if(controlConfArr[i].clazz){//如果控制器设置了样式名 this.clazzArr[i] = controlConfArr[i].clazz; if(parseInt(_config.activeItem) == i){//设置激活项 EJS.CssHelper.modifyName(cDom,controlConfArr[i].clazz[1]);//设置为激活样式 this.currentActiveControlDom = cDom; this.currentActiveControlDomIndex = i; }else{ EJS.CssHelper.modifyName(cDom,controlConfArr[i].clazz[0]);//设置为正常样式 } } } } //获取各场景DOM元素 speed delay effect direction var tagName = _config.tagName || this.tagName; var cnodes = dom.childNodes;//获取面板中所有一级子节点,从中筛选出场景 var scencIndex = 0; for(var i = 0; i < cnodes.length; i++){ var s = cnodes[i]; //if(EJS.Util.Format.lowercase(s.tagName) != EJS.Util.Format.lowercase(tagName)){continue;}//当子节点与预设置的tagName不同时,则进行过滤 if(!EJS.Fun.equalsIgnoreCase(s.tagName, tagName)){continue;}//当子节点与预设置的tagName不同时,则进行过滤 var attrStr = s.getAttribute("attr"); //场景配置信息的优先级 dom节点上的配置优先于手写配置 var scencConf = attrStr ? EJS.Util.Format.analyKV(attrStr) : (_config.scene && _config.scene[scencIndex]) ? _config.scene[scencIndex] : {}; var scencObj = new EJS.Effect.ScrollScene({ "domWidth" : s.offsetWidth ,"domHeight" : s.offsetHeight ,"direction" : scencConf["direction"] ? scencConf["direction"] : _config.direction ,"delay" : scencConf["delay"] ? scencConf["delay"] : _config.delay ,"speed" : scencConf["speed"] ? scencConf["speed"] : _config.speed ,"transition" : scencConf["transition"] ? scencConf["transition"] : _config.transition }); scencObj.setDom(s); scencObj.setPosition("absolute"); //scencObj.hide(); scencObj.setDomLeft(this.getDomWidth()) scencObj.setDomTop(this.getDomHeight()) this.addScene(scencObj); EJS.EventListener.add(scencObj.getDom(),"mouseover", EJS.FunctionHelper.bind(this,this.pause)); EJS.EventListener.add(scencObj.getDom(),"mouseout", EJS.FunctionHelper.bind(this,this.reStart)); scencIndex++; } if(this.sceneList && this.sceneList.size() > 1){ var activeItem_out = _config.activeItem >= 0 ? _config.activeItem : 0; var activeItem_in = (this.sceneList.size() + (activeItem_out - 1)) % this.sceneList.size(); if(this.getFirstAction() == "out"){//如果设置开始动作为出场,则将队列中的第一个场景设置为当前场景,并以面板左上角为圆点将其定位 this.setCurrentScene(this.getSceneByIndex(activeItem_out)); this.getCurrentScene().setDomLeft(0); this.getCurrentScene().setDomTop(0); this.getCurrentScene().display(); }else{ this.setCurrentScene(this.getSceneByIndex(activeItem_in)); } this.run(); } } } } EJS.ObjectHelper.extend(EJS.Effect.ScrollPanel, EJS.Effect.ScrollPanelBase); EJS.Effect.ScrollTransition = {}; EJS.Effect.ScrollTransition.tt1 = function(){ var callback ,currentScene ,standbyScene ,width ,height ,direction ,transition ,speed ,lineSpacing ,columnSpacing; function up(){//alert(standbyScene.getDomTop()) //alert(standbyScene.getDomTop()) JSTweener.addTween(currentScene.getDom().style ,{time: speed ,transition: transition //,onComplete: callback ,top:-height ,width:width ,height:height }); JSTweener.addTween(standbyScene.getDom().style ,{time: speed ,transition: transition ,onComplete: callback ,top:0 ,width:width ,height:height }); /* if(standbyScene.getDomTop() <= 0){ callback(); }else{ var x = standbyScene.getDomTop()-10; x = x < 0 ? 0 : x; currentScene.setDomTop(currentScene.getDomTop()-10); standbyScene.setDomTop(x); window.setTimeout(arguments.callee,speed); } */ } function down(){ JSTweener.addTween(currentScene.getDom().style ,{time: speed ,transition: transition //,onComplete: callback ,top:height ,width:width ,height:height }); JSTweener.addTween(standbyScene.getDom().style ,{time: speed ,transition: transition ,onComplete: callback ,top:0 ,width:width ,height:height }); /* if(standbyScene.getDomTop() >= 0){ callback(); }else{ var x = standbyScene.getDomTop()+10; x = x > 0 ? 0 : x; currentScene.setDomTop(currentScene.getDomTop()+10); standbyScene.setDomTop(x); window.setTimeout(arguments.callee,speed); } */ } function left(){ JSTweener.addTween(currentScene.getDom().style ,{time: speed ,transition: transition //,onComplete: callback ,left:-width ,width:width ,height:height }); JSTweener.addTween(standbyScene.getDom().style ,{time: speed ,transition: transition ,onComplete: callback ,left:0 ,width:width ,height:height }); /* if(standbyScene.getDomLeft() <= 0){ callback(); }else{ var y = standbyScene.getDomLeft()-10; y = y < 0 ? 0 : y; currentScene.setDomLeft(currentScene.getDomLeft()-10); standbyScene.setDomLeft(y); window.setTimeout(arguments.callee,speed); } */ } function right(){ JSTweener.addTween(currentScene.getDom().style ,{time: speed ,transition: transition //,onComplete: callback ,left:width ,width:width ,height:height }); JSTweener.addTween(standbyScene.getDom().style ,{time: speed ,transition: transition ,onComplete: callback ,left:0 ,width:width ,height:height }); /* if(standbyScene.getDomTop() >= 0){ callback(); }else{ var y = standbyScene.getDomLeft()+10; y = y > 0 ? 0 : y; currentScene.setDomLeft(currentScene.getDomLeft()+10); standbyScene.setDomLeft(y); window.setTimeout(arguments.callee,speed); } */ } return { /** *_callback:回调函数,当转场完成就执行回调函数 *_currentScene:当前场景 *_standbyScene:预备场景 *_config:参数对象 */ start : function(_callback, _currentScene, _standbyScene, _config){ callback = _callback;//回调方法 currentScene = _currentScene;//当前场景 standbyScene = _standbyScene;//预备场景 width = _config.width;//面板宽度 height = _config.height;//面板高度 direction = _config.direction;//预备场景的入场方向 transition = _config.transition//运动类型 speed = _config.speed;//入场动作的速度 lineSpacing = _config.lineSpacing;//两个场景间的行间距 columnSpacing = _config.columnSpacing;//两个场景间的列间距 standbyScene.display();//将预备场景设置为显示,为出场做准备 currentScene.getDom().style.width = width+"px"; currentScene.getDom().style.height = height+"px"; standbyScene.getDom().style.width = width+"px"; standbyScene.getDom().style.height = height+"px"; if(direction == "up"){ standbyScene.setDomLeft(0); standbyScene.setDomTop(height); up(); }else if(direction == "down"){ standbyScene.setDomLeft(0); standbyScene.setDomTop(-height); down(); }else if(direction == "left"){ standbyScene.setDomLeft(width); standbyScene.setDomTop(0); left(); }else if(direction == "right"){ standbyScene.setDomLeft(-width); standbyScene.setDomTop(0); right(); } } } }();