animation
Naboo is a front-end animation solution that includes animation scheduling mechanism and animation toolset, supports serial and parallel animations and callbacks, and supports custom plug-ins;
1. Statement
You can select and use classes and instances according to the scenario
var util = require('util');
// 类对象
var Naboo = util.naboo;
// 实例对象
var naboo = new util.naboo();
naboo.animate(...);
2. Use
1) naboo.animate(dom, prop, opt)
Parameters | Type | Required | Description |
---|
##dom | Object | is | The dom element that needs to be animated |
prop | Object | is | The css attribute key-value pair object that needs to be animated π |
opt | Object | No | Yes Selected animation parameter object |
opt.duration | number | No | Animation duration, default value 400, unit ms |
opt.ease | string | No | The easing function name of the animation, the default value is ease, optional values include ease , linear, ease-in, ease-out, ease-in-out |
opt.delay | number | No | Animation delay execution time, default value 0, unit ms |
opt.cb | Function | No | Animation completed The callback function after |
opt.mode | string | No | Animation mode, default value transition, optional value Including transition, keyframes (not yet supported), js (not yet supported) |
##Code sample
naboo.animate(dom, {
'transform': 'translateX(200px)'
}, {
duration: 2000,
ease: 'ease',
delay: 1000,
mode: 'transition',
cb: function() {
console.log(1);
}
}).start();
Description: Command function to start executing animation Parameter list:
ParametersType | Required | Description | |
fnFunction | No | Callback function after animation is completed | |
3) naboo.next()
Description: Let the animation go to the next A one-step instruction function. When calling the done or register (register plug-in) method, you need to call next() to enter the next animation;
Parameter list: None
Usage example:
naboo.animate(dom, { 'transform': 'translateX(200px)'
}, {
duration: 2000
}).done(function(next) {
console.log(1);
next();
});
4) naboo.cancel()
Description: Instruction to cancel animation, after calling this function , the currently unfinished animation will continue to be executed, and subsequent animations will not be executed
Parameter list: None
Usage example:
var instance;
btnStart.onclick = function () {
instance = naboo.animate(dom, {
'transform': 'translateX(200px)'
}, {
duration: 2000,
cb: function() {
console.log(1);
}
}).start();
}
btnCancel.onclick = function () {
instance.cancel();
}
5) naboo.on(name, fn)
##Parameter | Type | Required | Description |
##namestring | is the | event name | |
fnFunction | is the method for | event triggering | |
Description: Dismiss event Binding Parameter list:
##ParameterType | Required | Description | |
namestring | No | Event name, if empty, all events will be released | | fn
Function | No | Method for event triggering, if If empty, all events under the name will be released. | |
Usage example: var handle = function(event) {
console.log(event);
}
btn.onclick = function () {
console.log('解除事件');
naboo.off("customer", handle);
}
7) naboo.trigger (name, data)Description: Trigger eventParametersType | Required | Description | |
namestring | is the | event name. If it is empty, all events will be released. | | data
Object | No | Data that needs to be passed when triggering the event | |
##Usage example:
btn.onclick = function () {
naboo.trigger("customer", {
a: 1
});
}
8) naboo.p(list)Description: Naboo's parallel plug-in, through which multiple animations can be executed concurrently, and can be called through classes or instance objects
Parameter list:
##Parameter
TypeRequired | Description | | | list
array is a list of naboo objects that | needs to be parallelized | | Usage example:
naboo.p(
naboo.animate(dom1, {
'transform': 'translateX(200px)'
}, {
duration: 2000,
cb: function() {
console.log(1);
}
}),
naboo.animate(dom2, {
'transform': 'translateX(200px)'
}, {
duration: 3000,
cb: function() {
console.log(2);
}
})
).start();
8) naboo.done(fn)
Description: Naboo’s done Plug-in, can be used to call back after any animation plug-in, and can be called through a class or instance object;
Note: You need to call next()## in this method # Before entering the next animation, it is considered that there may be some asynchronous behavior, such as ajax request
- Parameter list:
##ParametersType | Required | Description | |
fnfunction | is the | callback function | |
##Usage example: naboo.animate(dom1, {
'transform': 'translateX(200px)'
}, {
duration: 2000,
cb: function() {
console.log(1);
}
}).done(function(next) {
console.log(2);
next();
}).animate(dom2, {
'transform': 'translateX(200px)'
}, {
duration: 2000,
ease: "ease",
cb: function() {
console.log(3);
}
}).start();
P.S.: The sample code identifies that the animation of dom2 will be executed after the animation of dom1 is completed3. Static method of the class: Naboo.register(name, fn)Description: Plug-in registration function, if animate cannot meet the needs, or the webmaster needs to encapsulate his own plug-in for easy calling, you can use this method to register the method; - Note: When implementing register fn, you need to call next() to execute the next animation;
- Parameter list:
ParametersType | Required | Description | |
fnfunction | is the | plug-in function, used to define the execution logic of the plug-in | |
Usage example: Naboo.register('animate', function (next, dom, prop, opt) {
opt = opt || {};
var cb = opt.cb;
opt.cb = function () {
cb && cb();
next();
};
opt.mode = ([
'transition'
].indexOf(opt.mode) > -1) ? opt.mode : 'transition';
Naboo[opt.mode](dom, prop, opt);
});