Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelvillar committed Jun 11, 2015
0 parents commit 22a6421
Show file tree
Hide file tree
Showing 5 changed files with 1,743 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib
node_modules
108 changes: 108 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Dynamics.js
Dynamics.js is a Javascript library to create physics-related CSS animations

To see some demos, check out [dynamicsjs.com](http://dynamicsjs.com).

## Usage
Include `dynamics.js` into your page: [download here](https://github.com/michaelvillar/dynamics.js/releases)
```
<script src="dynamics.js"></script>
```
Example:
```
var el = document.getElementById("logo")
dynamics.animate(el).to({
translateX: 350,
scale: 2,
opacity: 0.5
}, {
type: dynamic.Spring,
frequency: 200,
friction: 200,
duration: 1000
})
```

## Reference
### dynamics.animate(el, properties, options)
Animates an element to the properties with the animation options.
- `el` is a DOM element or any Javascript object
- `properties` is an object of the properties/values you want to animate
- `options` is an object representing the animation
- `type` is the [animation type](#dynamics-and-properties): `dynamics.spring`, `dynamics.easeInOut`,... (default: `dynamics.easeInOut`)
- `frequency`, `friction`, `bounciness`,... are specific to the animation type you are using
- `duration` is in milliseconds (default: `1000`)
- `complete` (optional) is the completion callback
- `change` (optional) is called at every change

### dynamics.stop(el)
Stops the animation applied on the element

### dynamics.css(el, properties)
This is applying the CSS properties to your element with the correct browser prefixes.
- `el` is a DOM element
- `properties` is an object of the CSS properties

### dynamics.setTimeout(fn, delay)
Dynamics.js has its own `setTimeout`. The reason is that `requestAnimationFrame` and `setTimeout` have different behaviors. In most browsers, `requestAnimationFrame` will not run in a background tab while `setTimeout` will. This can cause a lot of problems while using `setTimeout` along your animations. I suggest you use Dynamics's `setTimeout` and `clearTimeout` to handle these scenarios.
- `fn` is the callback
- `delay` is in milliseconds
Returns a unique id

### dynamics.clearTimeout(id)
Clears a timeout that was defined earlier
- `id` is the timeout id

## Dynamics and properties
### dynamics.spring
- `frequency`: default is 300
- `friction`: default is 200
- `anticipationSize` (optional)
- `anticipationStrength` (optional)

### dynamics.bounce
- `frequency`: default is 300
- `friction`: default is 200

### dynamics.forceWithGravity and dynamics.gravity
- `bounciness`: default is 400
- `elasticity`: default is 200

### dynamics.easeInOut, dynamics.easeIn and dynamics.easeOut
- `friction`: default is 500

### dynamics.linear
No properties

### dynamics.bezier
- `points`: array of points and control points

The easiest way to output this kind of array is to use the [curve creator](http://dynamicsjs.com). Here is an example:
```
[{"x":0,"y":0,"cp":[{"x":0.2,"y":0}]},
{"x":0.5,"y":-0.4,"cp":[{"x":0.4,"y":-0.4},{"x":0.8,"y":-0.4}]},
{"x":1,"y":1,"cp":[{"x":0.8,"y":1}]}]
```

## Contributing
Compile: `npm run build` or `npm run build:watch`

Run tests: `npm test`

## Browser Support
Tested on
[TODO]

## Sylvester
Some code from Sylvester.js has been used (part of Vector and Matrix).

## License
The MIT License (MIT)

Copyright (c) 2015 Michael Villar

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.
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "dynamics.js",
"title": "Dynamics.js",
"description": "Physics animation curves",
"version": "0.0.1",
"homepage": "http://dynamicsjs.com",
"author": {
"name": "Michael Villar"
},
"repository": {
"type": "git",
"url": "https://github.com/michaelvillar/dynamics.js"
},
"devDependencies": {
"coffee-script": "1.7.1",
"uglify-js": "2.4.14",
"jsdom": "3.x.x",
"mocha-jsdom": "0.4.0",
"chai": "3.0.0",
"mocha": "2.2.5"
},
"scripts": {
"test": "mocha --compilers coffee:coffee-script/register",
"build": "coffee -c -o ./lib/ ./src/dynamics.coffee && ./node_modules/uglify-js/bin/uglifyjs ./lib/dynamics.js -m -c -o ./lib/dynamics.min.js",
"build:watch": "coffee -w -c -o ./lib/ ./src/dynamics.coffee"
}
}
Loading

0 comments on commit 22a6421

Please sign in to comment.