If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-path-to-animation --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-path-to-animation');
Use to generate scss
files with predefined @keyframes animations by reading configuration of paths to be interpolated.
- Do you want to have smooth css animations you don't want to handle by java script?
- Do you need to pause them?
- Do you need to resize and keep the animated element's position?
- Do you want to write such animation manually? And rewrite them every time the client changes the design?
- Animations using translate instead of top/left positioning are considered as better performance and calculating translate movement manually could be painfully sometimes.
path-to-animation
needs just a JSON file with animations paths you would need and it will interpolate them and create the file with predefined @keyframes
animations you need.
Run this task with the grunt path-to-animation
command.
'path-to-animation': {
'customTask': {
// Points to the file containing animation path arrays
src: 'animation-paths.json',
// where to save the sass file when ready
dest: './output/outputfile.scss',
// property name to read from. It will be used for the css class name
// and for the css @keyframes name.
// the namespace should contain valid css class names characters
namespace: 'custom-namespace-name',
// we need the size of the animated element in order to calculate the translate values
elementSize: {
width: 100,
height: 100
},
// which sass mixin to @include (this should be created by the user)s
// the default is 'curved-animation'
sassMixin: 'sassence',
}
},
},
- Description: The JSON file contains animation path arrays
- Type:
String
- Default:
animation-paths.json
- Example file: JSON file example
- Description: The destination path for the output SASS file
- Type:
String
- Description: Current subtask namespace to read the animations from. It will be used for the generates
@keyframes
andcss
class name. - Type:
String
- Description: The Object contains
width
andheight
of the animated element. It's needed in order to calculate the path related to its size in percentages. - Type:
Object
- elementSize.width - Type:
Number|String
- elementSize.height - Type:
Number|String
- Description: The name of the sass mixin to be used for the generated css class.
- Type:
String
- Default:
curved-animation
Here is how we expect your JSON file to look like:
{
"custom-namespace-name": {
"item1": [50,50, 70,400, 500, 600, 100, 100],
"item2": [100, 200, 300, 400]
},
"another-namespace": {
"item1": [400,500, 600, 700]
}
}
// The path could be flat array in that format:
"item1": [x,y, x,y, x,y]
// or it could be nested:
"item2": [
[x,y],
[x,y]
]
The @keyframes name and the css class name will be as follows:
// the @keyframes:
@keyframes custom-namespace-name-item1 { ... }
// the class that will be applied to trigger the animation:
.animated-namespace-name-item1 { ... }
We depend on SASS. We expect the developers to use SASS in the project they plan to use path-to-animation
In order to give to the developers the freedom to add any animation rules to the generated animations without configuring templates we rely on using SASS for the generated content.
You will be obligated to provide sassMixin
for the mixin name you have created already.
There should be an existing sass code in your project containing mixin like this:
@mixin my-custom-mixin-name($animationName) {
animation-duration: 10s;
animation-delay: 300ms;
animation-name: $animationName
}
The Gruntfile configuration contains:
namespace: 'my-namespace',
sassMixin: 'my-custom-mixin-name',
When we are ready, we will generate css class for you containing:
@include my-custom-mixin-name(my-namespace-item1);
Run
npm install
npm test
- 0.1.1 - Synchronize version numbers between the
path-to-animation
modules - 0.1.0 - Separating
path-to-animation
in a separate module. There's no changes in the API. - 0.0.1 - Initial version
If you have any suggestions or the tool doesn't cover your needs, don't hasitate to fork us or send us an email opensource@mobilewaves.com. Every comment or contribution will be very appreciated.
Copyright (c) 2016 Mobile Wave Solutions (opensource@mobilewaves.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.