From dff15570f532a8c6c11f21f509e01fbc0cbac01e Mon Sep 17 00:00:00 2001 From: xiongwenjie Date: Fri, 13 Apr 2018 15:53:30 +0800 Subject: [PATCH] feat: add story inner animate function --- src/mip-story/animation-runner.js | 25 ++++++++------- src/mip-story/animation.js | 53 +++++++++---------------------- src/mip-story/page-advance.js | 5 --- 3 files changed, 28 insertions(+), 55 deletions(-) delete mode 100644 src/mip-story/page-advance.js diff --git a/src/mip-story/animation-runner.js b/src/mip-story/animation-runner.js index bf665facb..610641b59 100644 --- a/src/mip-story/animation-runner.js +++ b/src/mip-story/animation-runner.js @@ -3,8 +3,9 @@ * @author xiongwenjie@baidu.com * @description */ -define(function(require) { - 'use strict' +define(function (require) { + 'use strict'; + var css = require('util').css; function AnimationRunner(el, animationDef) { this.el = el; @@ -12,21 +13,21 @@ define(function(require) { this.isRunner = 1; this.create(); this.isStart = 0; - }; + } AnimationRunner.prototype.create = function () { var animationDef = this.animationDef; animationDef.easing.fill = 'forwards'; this.runner = this.el.animate(animationDef.keyframes, animationDef.easing); this.pause(); - } + }; - AnimationRunner.prototype.play = function() { + AnimationRunner.prototype.play = function () { var self = this; if (!self.isStart) { // delay属性会造成无法渲染第一帧,所以使用setTimeout来代替delay if (self.animationDef.delay) { - self.timer = setTimeout(function() { + self.timer = setTimeout(function () { css(self.el, {visibility: ''}); self.runner.play(); }, self.animationDef.delay); @@ -36,19 +37,19 @@ define(function(require) { } self.isStart = 1; } - } + }; - AnimationRunner.prototype.pause = function() { + AnimationRunner.prototype.pause = function () { this.runner.pause(); - } + }; - AnimationRunner.prototype.cancel = function() { + AnimationRunner.prototype.cancel = function () { var self = this; clearTimeout(self.timer); this.el.removeAttribute('style'); this.isStart = 0; this.runner.cancel(); - } + }; return AnimationRunner; -}); \ No newline at end of file +}); diff --git a/src/mip-story/animation.js b/src/mip-story/animation.js index 7eaadb32d..1b78ce334 100644 --- a/src/mip-story/animation.js +++ b/src/mip-story/animation.js @@ -3,7 +3,8 @@ * @author xiongwenjie@baidu.com * @description */ -define(function(require) { + +define(function (require) { 'use strict'; var animatePreset = require('./animate-preset'); @@ -17,7 +18,8 @@ define(function(require) { var MIP_STORY_ANIMATE_IN_AFTER_ATTR = 'animate-in-after'; var MIP_STORY_ANIMATE_IN_SELECROR = '[animate-in]'; - function AnimationManager (page) { + // @class + function AnimationManager(page) { this.page = page; // [ // { @@ -61,21 +63,18 @@ define(function(require) { player.runner.play(); } }); - } + }; - /** - * paintFirstFrame 渲染动画第一帧 - */ AnimationManager.prototype.paintFirstFrame = function () { - this.sequence.forEach(function(player) { + this.sequence.forEach(function (player) { css(player.runner.el, player.runner.animationDef.keyframes[0]); }); - } + }; AnimationManager.prototype.getRunnerById = function (id) { var runner = null; if (id) { - this.sequence.forEach(function(val) { + this.sequence.forEach(function (val) { if (val.id === id && val.runner && val.runner.isRunner) { runner = val.runner; } @@ -88,9 +87,9 @@ define(function(require) { this.sequence.forEach(function (player) { player.runner.cancel(); }); - } + }; - AnimationManager.prototype.waitAndStart = function(prevPlayer, player) { + AnimationManager.prototype.waitAndStart = function (prevPlayer, player) { var self = this; if (prevPlayer.runner && player.runner) { self.emitter.on(prevPlayer.el.id, function () { @@ -98,27 +97,15 @@ define(function(require) { }); prevPlayer.runner.onfinish = function () { self.emitter.trigger(prevPlayer.el.id); - } + }; } - } - + }; - /** - * hasAnimations 判断是否有动画 - * @param {nodeElement} element - * @return Boolean - */ function hasAnimations(element) { return !!element.querySelectorAll(MIP_STORY_ANIMATE_IN_SELECROR).length; } - /** - * [createAnimationDef description] - * @param {[type]} el [description] - * @param {[type]} preset [description] - * @return {[type]} [description] - */ - function createAnimationDef (el) { + function createAnimationDef(el) { var keyframes; var easing; @@ -157,11 +144,6 @@ define(function(require) { return animationDef; } - /** - * [getPreset description] - * @param {[type]} el [description] - * @return {[type]} [description] - */ function getPreset(el) { var animationDef = {}; var name = (String(el.getAttribute(MIP_STORY_ANIMATE_IN_ATTR)).split(/\s+/))[0]; @@ -169,12 +151,7 @@ define(function(require) { return animationDef; } - /** - * [buildRuner description] - * @param {[type]} animateDef [description] - * @return {[type]} [description] - */ - function buildRuner (el) { + function buildRuner(el) { var runner; var animationDef = createAnimationDef(el); runner = new AnimationRunner(el, animationDef); @@ -185,4 +162,4 @@ define(function(require) { AnimationManager: AnimationManager, hasAnimations: hasAnimations }; -}); \ No newline at end of file +}); diff --git a/src/mip-story/page-advance.js b/src/mip-story/page-advance.js deleted file mode 100644 index 9fbe3bfb7..000000000 --- a/src/mip-story/page-advance.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @file 页面切换的管理 - * @author xiongwenjie@baidu.com - * @description 页面的组件前进后退的管理逻辑 - */ \ No newline at end of file