DEMOcss
jsfiddlehtml
用 Matrix
生成一个二维矩阵,经过规定的运动形式,肯定出须要运动的点,触发特定事件,在特定时间后进行下一轮的运动,肯定运动点,触发事件,直到全部的点都运动过。git
参数说明github
option
一些配置信息options
说明浏览器
返回值说明缓存
Matrix
对象movePoint
函数参数说明:app
mChange.mode
列表中取option
): 肯定动画效果,能够不传,使用默认效果例子:dom
var app = document.getElementById('app') var urls = ['http://7xse2z.com1.z0.glb.clouddn.com/257084.jpg', 'http://7xse2z.com1.z0.glb.clouddn.com/257453.jpg', 'http://7xse2z.com1.z0.glb.clouddn.com/285848.jpg', 'http://7xse2z.com1.z0.glb.clouddn.com/3455%20%281%29.jpg'] var move = mChange.makeMatrixChange(app, { images: urls, row: 7, col: 9 }) // 使用默认的动画效果 move.movePoint(mChange.mode[0]) // 使用 transition 过渡,提供类名便可,eg: .test{transfrom:scale(0);} move.movePoint(mChange.mode[0], { className: 'test' }) // 使用 animation 动画,好比配合 animation.css 动画库 // animation 须要提供两个类名,进场动画和出场动画,同时须要标志这个是 animation 动画 move.movePoint(mChange.mode[0], { animate: true, classNameIn: 'animated flipInX', classNameOut: 'animated flipOutX' }) // 使用特定的图片进行动画 // 不传 image 则随机取传入的图片列表中的一张图片 move.movePoint(mChange.mode[0], { animate: true, classNameIn: 'animated flipInX', classNameOut: 'animated flipOutX', image: urls[0] })
makeMatrixChange
是使用 mChange
提供的方法写的一个函数,若是有需求自定义矩阵动画效果,能够使用提供的方法本身封装一个运动形式是一个对象,对象下包含信息函数
hitPoint
事件会将当前的运动形式放在回调函数的参数中。好比,定义了 duration
字段用于生成过渡的事件 dom.style.transition = mode.duration / 1000 + 's'
。一个简单的栗子动画
{ interval: '140', duration: '1000', init: function (row, col) { this.row = row this.col = col this.num = 0 }, check: function (i, j) { return i + j === this.num }, next: function () { this.num++ }, end: function () { return this.col + this.row + 1 === this.num } }
init
函数参数即为 Matrix
实例初始化的行列信息check
函数参数即为每一个二维矩阵的点,从 0
开始