Skip to content

Commit

Permalink
Add reverse option
Browse files Browse the repository at this point in the history
  • Loading branch information
micku7zu committed Jan 30, 2017
1 parent bb6fdc3 commit 9b18567
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A smooth 3D tilt javascript library forked from [Tilt.js (jQuery version)](https
### Options
```js
{
reverse: false, // reverse the tilt direction
max: 35, // max tilt rotation (degrees)
perspective: 1000, // Transform perspective, the lower the more extreme the tilt gets.
scale: 1, // 2 = 200%, 1.5 = 150%, etc..
Expand Down
9 changes: 6 additions & 3 deletions dist/vanilla-tilt.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var classCallCheck = function (instance, Constructor) {
* Created by Șandor Sergiu (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.1.0
* Version 1.2.0
*/

var VanillaTilt = function () {
Expand All @@ -35,6 +35,8 @@ var VanillaTilt = function () {
this.element = element;
this.settings = this.extendSettings(settings);

this.reverse = this.settings.reverse ? -1 : 1;

this.addEventListeners();
}

Expand Down Expand Up @@ -105,8 +107,8 @@ var VanillaTilt = function () {
x = Math.min(Math.max(x, 0), 1);
y = Math.min(Math.max(y, 0), 1);

var tiltX = (this.settings.max / 2 - x * this.settings.max).toFixed(2);
var tiltY = (y * this.settings.max - this.settings.max / 2).toFixed(2);
var tiltX = (this.reverse * (this.settings.max / 2 - x * this.settings.max)).toFixed(2);
var tiltY = (this.reverse * (y * this.settings.max - this.settings.max / 2)).toFixed(2);

return {
tiltX: tiltX,
Expand Down Expand Up @@ -149,6 +151,7 @@ var VanillaTilt = function () {

VanillaTilt.prototype.extendSettings = function extendSettings(settings) {
var defaultSettings = {
reverse: false,
max: 35,
perspective: 1000,
easing: "cubic-bezier(.03,.98,.52,.99)",
Expand Down
2 changes: 1 addition & 1 deletion dist/vanilla-tilt.babel.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions dist/vanilla-tilt.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var VanillaTilt = (function () {
* Created by Șandor Sergiu (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.1.0
* Version 1.2.0
*/

class VanillaTilt {
Expand All @@ -26,6 +26,8 @@ class VanillaTilt {
this.element = element;
this.settings = this.extendSettings(settings);

this.reverse = this.settings.reverse ? -1 : 1;

this.addEventListeners();
}

Expand Down Expand Up @@ -97,8 +99,8 @@ class VanillaTilt {
x = Math.min(Math.max(x, 0), 1);
y = Math.min(Math.max(y, 0), 1);

let tiltX = (this.settings.max / 2 - x * this.settings.max).toFixed(2);
let tiltY = (y * this.settings.max - this.settings.max / 2).toFixed(2);
let tiltX = (this.reverse * (this.settings.max / 2 - x * this.settings.max)).toFixed(2);
let tiltY = (this.reverse * (y * this.settings.max - this.settings.max / 2)).toFixed(2);

return {
tiltX: tiltX,
Expand Down Expand Up @@ -141,6 +143,7 @@ class VanillaTilt {

extendSettings(settings) {
let defaultSettings = {
reverse: false,
max: 35,
perspective: 1000,
easing: "cubic-bezier(.03,.98,.52,.99)",
Expand Down
2 changes: 1 addition & 1 deletion dist/vanilla-tilt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vanilla-tilt",
"version": "1.1.0",
"version": "1.2.0",
"description": "A smooth 3D tilt javascript library forked from Tilt.js",
"main": "lib/vanilla-tilt.js",
"dist": "dist/vanilla-tilt.js",
Expand Down
9 changes: 6 additions & 3 deletions src/vanilla-tilt.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by Șandor Sergiu (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.1.0
* Version 1.2.0
*/

export default class VanillaTilt {
Expand All @@ -23,6 +23,8 @@ export default class VanillaTilt {
this.element = element;
this.settings = this.extendSettings(settings);

this.reverse = this.settings.reverse ? -1 : 1;

this.addEventListeners();
}

Expand Down Expand Up @@ -94,8 +96,8 @@ export default class VanillaTilt {
x = Math.min(Math.max(x, 0), 1);
y = Math.min(Math.max(y, 0), 1);

let tiltX = (this.settings.max / 2 - x * this.settings.max).toFixed(2);
let tiltY = (y * this.settings.max - this.settings.max / 2).toFixed(2);
let tiltX = (this.reverse * (this.settings.max / 2 - x * this.settings.max)).toFixed(2);
let tiltY = (this.reverse * (y * this.settings.max - this.settings.max / 2)).toFixed(2);

return {
tiltX: tiltX,
Expand Down Expand Up @@ -138,6 +140,7 @@ export default class VanillaTilt {

extendSettings(settings) {
let defaultSettings = {
reverse: false,
max: 35,
perspective: 1000,
easing: "cubic-bezier(.03,.98,.52,.99)",
Expand Down

0 comments on commit 9b18567

Please sign in to comment.