Compare commits

...

23 commits

Author SHA1 Message Date
Șandor Sergiu 48f4ee931d
Update README.md 2023-11-05 05:55:04 +02:00
micku7zu 967ab1accf Fix destroy method and update to version 1.8.1 2023-08-15 12:47:15 +03:00
micku7zu f4a557955d Update package-lock.json 2022-12-13 01:08:45 +02:00
micku7zu 7a179baa43 Update to version 1.8.0 2022-12-13 01:08:35 +02:00
micku7zu bfe0c75eb5 Add Andžs Pilskalns to contributors 2022-12-13 01:06:18 +02:00
micku7zu 2a1f867ec1 Update reset-to-start default to true 2022-12-13 01:00:15 +02:00
dependabot[bot] 042c3eac64
Bump decode-uri-component from 0.2.0 to 0.2.2 (#124)
Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2.
- [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases)
- [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2)

---
updated-dependencies:
- dependency-name: decode-uri-component
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-13 00:30:46 +02:00
dependabot[bot] 0c73694cb8
Bump qs and gh-pages (#125)
Bumps [qs](https://github.com/ljharb/qs) to 6.5.3 and updates ancestor dependency [gh-pages](https://github.com/tschaub/gh-pages). These dependencies need to be updated together.


Updates `qs` from 6.5.2 to 6.5.3
- [Release notes](https://github.com/ljharb/qs/releases)
- [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md)
- [Commits](https://github.com/ljharb/qs/compare/v6.5.2...v6.5.3)

Updates `gh-pages` from 0.12.0 to 4.0.0
- [Release notes](https://github.com/tschaub/gh-pages/releases)
- [Changelog](https://github.com/tschaub/gh-pages/blob/main/changelog.md)
- [Commits](https://github.com/tschaub/gh-pages/compare/v0.12.0...v4.0.0)

---
updated-dependencies:
- dependency-name: qs
  dependency-type: indirect
- dependency-name: gh-pages
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-12-13 00:30:37 +02:00
Andžs 475fa30d50
Feature: "reset to start" (#126) 2022-12-13 00:28:57 +02:00
PSJahn ffc28a5bab
Removed unnecessary commas triggering my OCD (#119) 2022-11-03 09:46:11 +02:00
micku7zu 7f606cd52d Update to version 1.7.3 2022-10-29 20:37:19 +03:00
Rosux e80bf21faa
Fix glare on elements with border-radius 2022-10-29 20:21:18 +03:00
Șandor Sergiu 82792cbc9e
Update vanilla-tilt.js 2022-10-27 14:05:23 +03:00
Șandor Sergiu 29d586ce5b
Update README.md 2022-10-27 14:04:15 +03:00
Sheryl Hohman 6315937c6e
typo in README.md (#102) 2022-02-20 20:10:54 +02:00
Șandor Sergiu 61559a399a
Update README.md 2022-01-10 10:03:38 +02:00
Șandor Sergiu 2ee96e937f
Update README.md 2022-01-10 09:59:12 +02:00
Șandor Sergiu f6b73dac54
Revert "Add setting to use px instead of degrees for tilt (#94)" (#97)
This reverts commit 43ca5c53cf.
2021-11-03 09:14:50 +02:00
Eric Castillo 43ca5c53cf
Add setting to use px instead of degrees for tilt (#94) 2021-11-03 09:06:31 +02:00
micku7zu cb1f298d83 Update to 1.7.2 2021-09-04 10:26:25 +03:00
dependabot[bot] 66f7af8fa1
Bump path-parse from 1.0.5 to 1.0.7 (#92)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.5 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-04 10:25:45 +03:00
micku7zu ebcf46cec4 Update to 1.7.2 2021-09-04 10:25:03 +03:00
Foxi 20f9edad9e
Fixing glare being too small when the container's vertical dimension is greater than its horizontal. (#91) 2021-09-04 09:57:02 +03:00
14 changed files with 7311 additions and 341 deletions

View file

@ -5,3 +5,4 @@
- [Matteo Rigon](https://github.com/matteo-rigon) (Device orientation support)
- [Corey Austin](https://github.com/lazyhummingbird) (Initial gyroscope position)
- [rrroyal](https://github.com/rrroyal) (Whole document mouse events listening)
- [Andžs Pilskalns](https://github.com/Pilskalns) ("reset-to-start" feature)

View file

@ -31,14 +31,15 @@ If you want to use this library in IE, you need to include a CustomEvent polyfil
scale: 1, // 2 = 200%, 1.5 = 150%, etc..
speed: 300, // Speed of the enter/exit transition
transition: true, // Set a transition on enter/exit.
axis: null, // What axis should be disabled. Can be X or Y.
axis: null, // What axis should be enabled. Can be "x" or "y".
reset: true, // If the tilt effect has to be reset on exit.
"reset-to-start": true, // Whether the exit reset will go to [0,0] (default) or [startX, startY]
easing: "cubic-bezier(.03,.98,.52,.99)", // Easing on enter/exit.
glare: false, // if it should have a "glare" effect
"max-glare": 1, // the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
"glare-prerender": false, // false = VanillaTilt creates the glare elements for you, otherwise
// you need to add .js-tilt-glare>.js-tilt-glare-inner by yourself
"mouse-event-element": null, // css-selector or link to HTML-element what will be listen mouse events
"mouse-event-element": null, // css-selector or link to an HTML-element that will be listening to mouse events
"full-page-listening": false, // If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
gyroscope: true, // Boolean to enable/disable device orientation detection,
gyroscopeMinAngleX: -45, // This is the bottom limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the left border of the element;
@ -114,7 +115,17 @@ Original library author: [Gijs Rogé](https://twitter.com/GijsRoge)
- [Corey Austin](https://github.com/lazyhummingbird) (Initial gyroscope position)
- [Sander Moolin](https://github.com/SaFrMo)
- [rrroyal](https://github.com/rrroyal) (Whole document mouse events listening)
- [Andžs Pilskalns](https://github.com/Pilskalns) ("reset-to-start" feature)
### Other projects
#### [Quick Cursor: One-Handed mode](https://play.google.com/store/apps/details?id=com.quickcursor) (Android app)
Play Store link: https://play.google.com/store/apps/details?id=com.quickcursor
### Buy me a beer 🍻
If you want to thank me for vanilla-tilt.js or Quick Cursor Android app, you can donate on PayPal:
- [Donate through PayPal](https://www.paypal.com/donate/?hosted_button_id=XH38XJ986LQFA): https://www.paypal.com/donate/?hosted_button_id=XH38XJ986LQFA
- [Send money through PayPal](https://www.paypal.com/paypalme/micku7zu?locale.x=en_US): https://www.paypal.com/paypalme/micku7zu?locale.x=en_US
### License
MIT License

View file

@ -11,7 +11,7 @@ var classCallCheck = function (instance, Constructor) {
* Created by Sergiu Șandor (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.7.1
* Version 1.8.1
*/
var VanillaTilt = function () {
@ -47,6 +47,7 @@ var VanillaTilt = function () {
this.settings = this.extendSettings(settings);
this.reverse = this.settings.reverse ? -1 : 1;
this.resetToStart = VanillaTilt.isSettingTrue(this.settings["reset-to-start"]);
this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
@ -65,7 +66,11 @@ var VanillaTilt = function () {
this.addEventListeners();
this.reset();
this.updateInitialPosition();
if (this.resetToStart === false) {
this.settings.startX = 0;
this.settings.startY = 0;
}
}
VanillaTilt.isSettingTrue = function isSettingTrue(setting) {
@ -149,7 +154,10 @@ var VanillaTilt = function () {
cancelAnimationFrame(this.updateCall);
}
this.reset();
this.element.style.willChange = "";
this.element.style.transition = "";
this.element.style.transform = "";
this.resetGlare();
this.removeEventListeners();
this.element.vanillaTilt = null;
@ -228,30 +236,6 @@ var VanillaTilt = function () {
};
VanillaTilt.prototype.reset = function reset() {
this.event = {
clientX: this.left + this.width / 2,
clientY: this.top + this.height / 2
};
if (this.element && this.element.style) {
this.element.style.transform = "perspective(" + this.settings.perspective + "px) " + "rotateX(0deg) " + "rotateY(0deg) " + "scale3d(1, 1, 1)";
}
this.resetGlare();
};
VanillaTilt.prototype.resetGlare = function resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
};
VanillaTilt.prototype.updateInitialPosition = function updateInitialPosition() {
if (this.settings.startX === 0 && this.settings.startY === 0) {
return;
}
this.onMouseEnter();
if (this.fullPageListening) {
@ -273,6 +257,13 @@ var VanillaTilt = function () {
this.resetGlare();
};
VanillaTilt.prototype.resetGlare = function resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
};
VanillaTilt.prototype.getValues = function getValues() {
var x = void 0,
y = void 0;
@ -361,7 +352,8 @@ var VanillaTilt = function () {
"width": "100%",
"height": "100%",
"overflow": "hidden",
"pointer-events": "none"
"pointer-events": "none",
"border-radius": "inherit"
});
Object.assign(this.glareElement.style, {
@ -370,19 +362,21 @@ var VanillaTilt = function () {
"left": "50%",
"pointer-events": "none",
"background-image": "linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)",
"width": this.element.offsetWidth * 2 + "px",
"height": this.element.offsetWidth * 2 + "px",
"transform": "rotate(180deg) translate(-50%, -50%)",
"transform-origin": "0% 0%",
"opacity": "0"
});
this.updateGlareSize();
};
VanillaTilt.prototype.updateGlareSize = function updateGlareSize() {
if (this.glare) {
var glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
Object.assign(this.glareElement.style, {
"width": "" + this.element.offsetWidth * 2,
"height": "" + this.element.offsetWidth * 2
"width": glareSize + "px",
"height": glareSize + "px"
});
}
};
@ -424,13 +418,14 @@ var VanillaTilt = function () {
* @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
* @param {number} settings.speed - Speed of the enter/exit transition
* @param {boolean} settings.transition - Set a transition on enter/exit
* @param {string|null} settings.axis - What axis should be disabled. Can be X or Y
* @param {boolean} settings.glare - What axis should be disabled. Can be X or Y
* @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
* @param {boolean} settings.glare - if it should have a "glare" effect
* @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
* @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
* @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
* @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
* @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
* @param {boolean} settings.reset-to-start - true = On reset event (mouse leave) will return to initial start angle (if startX or startY is set)
* @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
* @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
* @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
@ -455,6 +450,7 @@ var VanillaTilt = function () {
"full-page-listening": false,
"mouse-event-element": null,
reset: true,
"reset-to-start": true,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,

File diff suppressed because one or more lines are too long

71
dist/vanilla-tilt.js vendored
View file

@ -5,7 +5,7 @@ var VanillaTilt = (function () {
* Created by Sergiu Șandor (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.7.1
* Version 1.8.1
*/
class VanillaTilt {
@ -38,6 +38,7 @@ class VanillaTilt {
this.settings = this.extendSettings(settings);
this.reverse = this.settings.reverse ? -1 : 1;
this.resetToStart = VanillaTilt.isSettingTrue(this.settings["reset-to-start"]);
this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
@ -55,7 +56,12 @@ class VanillaTilt {
}
this.addEventListeners();
this.updateInitialPosition();
this.reset();
if (this.resetToStart === false) {
this.settings.startX = 0;
this.settings.startY = 0;
}
}
static isSettingTrue(setting) {
@ -133,7 +139,10 @@ class VanillaTilt {
cancelAnimationFrame(this.updateCall);
}
this.reset();
this.element.style.willChange = "";
this.element.style.transition = "";
this.element.style.transform = "";
this.resetGlare();
this.removeEventListeners();
this.element.vanillaTilt = null;
@ -212,33 +221,6 @@ class VanillaTilt {
}
reset() {
this.event = {
clientX: this.left + this.width / 2,
clientY: this.top + this.height / 2
};
if (this.element && this.element.style) {
this.element.style.transform = `perspective(${this.settings.perspective}px) ` +
`rotateX(0deg) ` +
`rotateY(0deg) ` +
`scale3d(1, 1, 1)`;
}
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
updateInitialPosition() {
if (this.settings.startX === 0 && this.settings.startY === 0) {
return;
}
this.onMouseEnter();
if (this.fullPageListening) {
@ -253,7 +235,6 @@ class VanillaTilt {
};
}
let backupScale = this.settings.scale;
this.settings.scale = 1;
this.update();
@ -261,6 +242,13 @@ class VanillaTilt {
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
getValues() {
let x, y;
@ -349,7 +337,8 @@ class VanillaTilt {
"width": "100%",
"height": "100%",
"overflow": "hidden",
"pointer-events": "none"
"pointer-events": "none",
"border-radius": "inherit"
});
Object.assign(this.glareElement.style, {
@ -358,19 +347,21 @@ class VanillaTilt {
"left": "50%",
"pointer-events": "none",
"background-image": `linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)`,
"width": `${this.element.offsetWidth * 2}px`,
"height": `${this.element.offsetWidth * 2}px`,
"transform": "rotate(180deg) translate(-50%, -50%)",
"transform-origin": "0% 0%",
"opacity": "0",
"opacity": "0"
});
this.updateGlareSize();
}
updateGlareSize() {
if (this.glare) {
const glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
Object.assign(this.glareElement.style, {
"width": `${this.element.offsetWidth * 2}`,
"height": `${this.element.offsetWidth * 2}`,
"width": `${glareSize}px`,
"height": `${glareSize}px`,
});
}
}
@ -415,13 +406,14 @@ class VanillaTilt {
* @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
* @param {number} settings.speed - Speed of the enter/exit transition
* @param {boolean} settings.transition - Set a transition on enter/exit
* @param {string|null} settings.axis - What axis should be disabled. Can be X or Y
* @param {boolean} settings.glare - What axis should be disabled. Can be X or Y
* @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
* @param {boolean} settings.glare - if it should have a "glare" effect
* @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
* @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
* @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
* @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
* @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
* @param {boolean} settings.reset-to-start - true = On reset event (mouse leave) will return to initial start angle (if startX or startY is set)
* @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
* @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
* @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
@ -444,6 +436,7 @@ class VanillaTilt {
"full-page-listening": false,
"mouse-event-element": null,
reset: true,
"reset-to-start": true,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,

File diff suppressed because one or more lines are too long

View file

@ -31,14 +31,15 @@ If you want to use this library in IE, you need to include a CustomEvent polyfil
scale: 1, // 2 = 200%, 1.5 = 150%, etc..
speed: 300, // Speed of the enter/exit transition
transition: true, // Set a transition on enter/exit.
axis: null, // What axis should be disabled. Can be X or Y.
axis: null, // What axis should be enabled. Can be "x" or "y".
reset: true, // If the tilt effect has to be reset on exit.
"reset-to-start": true, // Whether the exit reset will go to [0,0] (default) or [startX, startY]
easing: "cubic-bezier(.03,.98,.52,.99)", // Easing on enter/exit.
glare: false, // if it should have a "glare" effect
"max-glare": 1, // the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
"glare-prerender": false, // false = VanillaTilt creates the glare elements for you, otherwise
// you need to add .js-tilt-glare>.js-tilt-glare-inner by yourself
"mouse-event-element": null, // css-selector or link to HTML-element what will be listen mouse events
"mouse-event-element": null, // css-selector or link to an HTML-element that will be listening to mouse events
"full-page-listening": false, // If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
gyroscope: true, // Boolean to enable/disable device orientation detection,
gyroscopeMinAngleX: -45, // This is the bottom limit of the device angle on X axis, meaning that a device rotated at this angle would tilt the element as if the mouse was on the left border of the element;
@ -114,6 +115,15 @@ Original library author: [Gijs Rogé](https://twitter.com/GijsRoge)
- [Corey Austin](https://github.com/lazyhummingbird) (Initial gyroscope position)
- [Sander Moolin](https://github.com/SaFrMo)
- [rrroyal](https://github.com/rrroyal) (Whole document mouse events listening)
- [Andžs Pilskalns](https://github.com/Pilskalns) ("reset-to-start" feature)
### Other projects
#### [Quick Cursor: One-Handed mode](https://play.google.com/store/apps/details?id=com.quickcursor) (Android app)
Play Store link: https://play.google.com/store/apps/details?id=com.quickcursor
### Buy me a beer 🍻
If you want to thank me for vanilla-tilt.js or Quick Cursor Android app, you can [donate on PayPal](https://www.paypal.me/micku7zu?locale.x=en_US): https://www.paypal.me/micku7zu?locale.x=en_US
### License

View file

@ -2,7 +2,7 @@
* Created by Sergiu Șandor (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.7.1
* Version 1.8.1
*/
class VanillaTilt {
@ -35,6 +35,7 @@ class VanillaTilt {
this.settings = this.extendSettings(settings);
this.reverse = this.settings.reverse ? -1 : 1;
this.resetToStart = VanillaTilt.isSettingTrue(this.settings["reset-to-start"]);
this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
@ -53,7 +54,11 @@ class VanillaTilt {
this.addEventListeners();
this.reset();
this.updateInitialPosition();
if (this.resetToStart === false) {
this.settings.startX = 0;
this.settings.startY = 0;
}
}
static isSettingTrue(setting) {
@ -131,7 +136,10 @@ class VanillaTilt {
cancelAnimationFrame(this.updateCall);
}
this.reset();
this.element.style.willChange = "";
this.element.style.transition = "";
this.element.style.transform = "";
this.resetGlare();
this.removeEventListeners();
this.element.vanillaTilt = null;
@ -210,33 +218,6 @@ class VanillaTilt {
}
reset() {
this.event = {
clientX: this.left + this.width / 2,
clientY: this.top + this.height / 2
};
if (this.element && this.element.style) {
this.element.style.transform = `perspective(${this.settings.perspective}px) ` +
`rotateX(0deg) ` +
`rotateY(0deg) ` +
`scale3d(1, 1, 1)`;
}
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
updateInitialPosition() {
if (this.settings.startX === 0 && this.settings.startY === 0) {
return;
}
this.onMouseEnter();
if (this.fullPageListening) {
@ -251,7 +232,6 @@ class VanillaTilt {
};
}
let backupScale = this.settings.scale;
this.settings.scale = 1;
this.update();
@ -259,6 +239,13 @@ class VanillaTilt {
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
getValues() {
let x, y;
@ -347,7 +334,8 @@ class VanillaTilt {
"width": "100%",
"height": "100%",
"overflow": "hidden",
"pointer-events": "none"
"pointer-events": "none",
"border-radius": "inherit"
});
Object.assign(this.glareElement.style, {
@ -356,19 +344,21 @@ class VanillaTilt {
"left": "50%",
"pointer-events": "none",
"background-image": `linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)`,
"width": `${this.element.offsetWidth * 2}px`,
"height": `${this.element.offsetWidth * 2}px`,
"transform": "rotate(180deg) translate(-50%, -50%)",
"transform-origin": "0% 0%",
"opacity": "0",
"opacity": "0"
});
this.updateGlareSize();
}
updateGlareSize() {
if (this.glare) {
const glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
Object.assign(this.glareElement.style, {
"width": `${this.element.offsetWidth * 2}`,
"height": `${this.element.offsetWidth * 2}`,
"width": `${glareSize}px`,
"height": `${glareSize}px`,
});
}
}
@ -413,13 +403,14 @@ class VanillaTilt {
* @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
* @param {number} settings.speed - Speed of the enter/exit transition
* @param {boolean} settings.transition - Set a transition on enter/exit
* @param {string|null} settings.axis - What axis should be disabled. Can be X or Y
* @param {boolean} settings.glare - What axis should be disabled. Can be X or Y
* @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
* @param {boolean} settings.glare - if it should have a "glare" effect
* @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
* @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
* @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
* @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
* @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
* @param {boolean} settings.reset-to-start - true = On reset event (mouse leave) will return to initial start angle (if startX or startY is set)
* @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
* @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
* @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
@ -442,6 +433,7 @@ class VanillaTilt {
"full-page-listening": false,
"mouse-event-element": null,
reset: true,
"reset-to-start": true,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,

View file

@ -10,7 +10,7 @@ var classCallCheck = function (instance, Constructor) {
* Created by Sergiu Șandor (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.7.1
* Version 1.8.1
*/
var VanillaTilt = function () {
@ -46,6 +46,7 @@ var VanillaTilt = function () {
this.settings = this.extendSettings(settings);
this.reverse = this.settings.reverse ? -1 : 1;
this.resetToStart = VanillaTilt.isSettingTrue(this.settings["reset-to-start"]);
this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
@ -64,7 +65,11 @@ var VanillaTilt = function () {
this.addEventListeners();
this.reset();
this.updateInitialPosition();
if (this.resetToStart === false) {
this.settings.startX = 0;
this.settings.startY = 0;
}
}
VanillaTilt.isSettingTrue = function isSettingTrue(setting) {
@ -148,7 +153,10 @@ var VanillaTilt = function () {
cancelAnimationFrame(this.updateCall);
}
this.reset();
this.element.style.willChange = "";
this.element.style.transition = "";
this.element.style.transform = "";
this.resetGlare();
this.removeEventListeners();
this.element.vanillaTilt = null;
@ -227,30 +235,6 @@ var VanillaTilt = function () {
};
VanillaTilt.prototype.reset = function reset() {
this.event = {
clientX: this.left + this.width / 2,
clientY: this.top + this.height / 2
};
if (this.element && this.element.style) {
this.element.style.transform = "perspective(" + this.settings.perspective + "px) " + "rotateX(0deg) " + "rotateY(0deg) " + "scale3d(1, 1, 1)";
}
this.resetGlare();
};
VanillaTilt.prototype.resetGlare = function resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
};
VanillaTilt.prototype.updateInitialPosition = function updateInitialPosition() {
if (this.settings.startX === 0 && this.settings.startY === 0) {
return;
}
this.onMouseEnter();
if (this.fullPageListening) {
@ -272,6 +256,13 @@ var VanillaTilt = function () {
this.resetGlare();
};
VanillaTilt.prototype.resetGlare = function resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
};
VanillaTilt.prototype.getValues = function getValues() {
var x = void 0,
y = void 0;
@ -360,7 +351,8 @@ var VanillaTilt = function () {
"width": "100%",
"height": "100%",
"overflow": "hidden",
"pointer-events": "none"
"pointer-events": "none",
"border-radius": "inherit"
});
Object.assign(this.glareElement.style, {
@ -369,19 +361,21 @@ var VanillaTilt = function () {
"left": "50%",
"pointer-events": "none",
"background-image": "linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)",
"width": this.element.offsetWidth * 2 + "px",
"height": this.element.offsetWidth * 2 + "px",
"transform": "rotate(180deg) translate(-50%, -50%)",
"transform-origin": "0% 0%",
"opacity": "0"
});
this.updateGlareSize();
};
VanillaTilt.prototype.updateGlareSize = function updateGlareSize() {
if (this.glare) {
var glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
Object.assign(this.glareElement.style, {
"width": "" + this.element.offsetWidth * 2,
"height": "" + this.element.offsetWidth * 2
"width": glareSize + "px",
"height": glareSize + "px"
});
}
};
@ -423,13 +417,14 @@ var VanillaTilt = function () {
* @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
* @param {number} settings.speed - Speed of the enter/exit transition
* @param {boolean} settings.transition - Set a transition on enter/exit
* @param {string|null} settings.axis - What axis should be disabled. Can be X or Y
* @param {boolean} settings.glare - What axis should be disabled. Can be X or Y
* @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
* @param {boolean} settings.glare - if it should have a "glare" effect
* @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
* @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
* @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
* @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
* @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
* @param {boolean} settings.reset-to-start - true = On reset event (mouse leave) will return to initial start angle (if startX or startY is set)
* @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
* @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
* @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
@ -454,6 +449,7 @@ var VanillaTilt = function () {
"full-page-listening": false,
"mouse-event-element": null,
reset: true,
"reset-to-start": true,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,

7263
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
{
"name": "vanilla-tilt",
"version": "1.7.1",
"version": "1.8.1",
"description": "A smooth 3D tilt javascript library forked from Tilt.js",
"main": "lib/vanilla-tilt.js",
"module_es2015": "lib/vanilla-tilt.es2015.js",
@ -29,7 +29,7 @@
"babelrc-rollup": "^3.0.0",
"cash-cp": "^0.2.0",
"cross-env": "^3.1.4",
"gh-pages": "^0.12.0",
"gh-pages": "^4.0.0",
"release-script": "^1.0.2",
"rollup": "^0.41.4",
"rollup-plugin-babel": "^2.7.1",

View file

@ -2,7 +2,7 @@
* Created by Sergiu Șandor (micku7zu) on 1/27/2017.
* Original idea: https://github.com/gijsroge/tilt.js
* MIT License.
* Version 1.7.1
* Version 1.8.1
*/
export default class VanillaTilt {
@ -35,6 +35,7 @@ export default class VanillaTilt {
this.settings = this.extendSettings(settings);
this.reverse = this.settings.reverse ? -1 : 1;
this.resetToStart = VanillaTilt.isSettingTrue(this.settings["reset-to-start"]);
this.glare = VanillaTilt.isSettingTrue(this.settings.glare);
this.glarePrerender = VanillaTilt.isSettingTrue(this.settings["glare-prerender"]);
this.fullPageListening = VanillaTilt.isSettingTrue(this.settings["full-page-listening"]);
@ -53,7 +54,11 @@ export default class VanillaTilt {
this.addEventListeners();
this.reset();
this.updateInitialPosition();
if (this.resetToStart === false) {
this.settings.startX = 0;
this.settings.startY = 0;
}
}
static isSettingTrue(setting) {
@ -131,7 +136,10 @@ export default class VanillaTilt {
cancelAnimationFrame(this.updateCall);
}
this.reset();
this.element.style.willChange = "";
this.element.style.transition = "";
this.element.style.transform = "";
this.resetGlare();
this.removeEventListeners();
this.element.vanillaTilt = null;
@ -210,33 +218,6 @@ export default class VanillaTilt {
}
reset() {
this.event = {
clientX: this.left + this.width / 2,
clientY: this.top + this.height / 2
};
if (this.element && this.element.style) {
this.element.style.transform = `perspective(${this.settings.perspective}px) ` +
`rotateX(0deg) ` +
`rotateY(0deg) ` +
`scale3d(1, 1, 1)`;
}
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
updateInitialPosition() {
if (this.settings.startX === 0 && this.settings.startY === 0) {
return;
}
this.onMouseEnter();
if (this.fullPageListening) {
@ -251,7 +232,6 @@ export default class VanillaTilt {
};
}
let backupScale = this.settings.scale;
this.settings.scale = 1;
this.update();
@ -259,6 +239,13 @@ export default class VanillaTilt {
this.resetGlare();
}
resetGlare() {
if (this.glare) {
this.glareElement.style.transform = "rotate(180deg) translate(-50%, -50%)";
this.glareElement.style.opacity = "0";
}
}
getValues() {
let x, y;
@ -347,7 +334,8 @@ export default class VanillaTilt {
"width": "100%",
"height": "100%",
"overflow": "hidden",
"pointer-events": "none"
"pointer-events": "none",
"border-radius": "inherit"
});
Object.assign(this.glareElement.style, {
@ -356,19 +344,21 @@ export default class VanillaTilt {
"left": "50%",
"pointer-events": "none",
"background-image": `linear-gradient(0deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%)`,
"width": `${this.element.offsetWidth * 2}px`,
"height": `${this.element.offsetWidth * 2}px`,
"transform": "rotate(180deg) translate(-50%, -50%)",
"transform-origin": "0% 0%",
"opacity": "0",
"opacity": "0"
});
this.updateGlareSize();
}
updateGlareSize() {
if (this.glare) {
const glareSize = (this.element.offsetWidth > this.element.offsetHeight ? this.element.offsetWidth : this.element.offsetHeight) * 2;
Object.assign(this.glareElement.style, {
"width": `${this.element.offsetWidth * 2}`,
"height": `${this.element.offsetWidth * 2}`,
"width": `${glareSize}px`,
"height": `${glareSize}px`,
});
}
}
@ -413,13 +403,14 @@ export default class VanillaTilt {
* @param {number} settings.scale - 2 = 200%, 1.5 = 150%, etc..
* @param {number} settings.speed - Speed of the enter/exit transition
* @param {boolean} settings.transition - Set a transition on enter/exit
* @param {string|null} settings.axis - What axis should be disabled. Can be X or Y
* @param {boolean} settings.glare - What axis should be disabled. Can be X or Y
* @param {string|null} settings.axis - What axis should be enabled. Can be "x" or "y"
* @param {boolean} settings.glare - if it should have a "glare" effect
* @param {number} settings.max-glare - the maximum "glare" opacity (1 = 100%, 0.5 = 50%)
* @param {boolean} settings.glare-prerender - false = VanillaTilt creates the glare elements for you, otherwise
* @param {boolean} settings.full-page-listening - If true, parallax effect will listen to mouse move events on the whole document, not only the selected element
* @param {string|object} settings.mouse-event-element - String selector or link to HTML-element what will be listen mouse events
* @param {boolean} settings.reset - false = If the tilt effect has to be reset on exit
* @param {boolean} settings.reset-to-start - true = On reset event (mouse leave) will return to initial start angle (if startX or startY is set)
* @param {gyroscope} settings.gyroscope - Enable tilting by deviceorientation events
* @param {gyroscopeSensitivity} settings.gyroscopeSensitivity - Between 0 and 1 - The angle at which max tilt position is reached. 1 = 90deg, 0.5 = 45deg, etc..
* @param {gyroscopeSamples} settings.gyroscopeSamples - How many gyroscope moves to decide the starting position.
@ -442,6 +433,7 @@ export default class VanillaTilt {
"full-page-listening": false,
"mouse-event-element": null,
reset: true,
"reset-to-start": true,
gyroscope: true,
gyroscopeMinAngleX: -45,
gyroscopeMaxAngleX: 45,

View file

@ -1,6 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
@ -129,7 +128,8 @@
data-tilt-scale="1.1"
data-tilt-perspective="500"
data-tilt-max="15"
data-tilt-scale="1.1"
data-tilt-startX="15"
data-tilt-startY="30"
>
<span>vanilla-tilt.js</span>
</a>

8
vanilla-tilt.d.ts vendored
View file

@ -1,4 +1,4 @@
// Extended Type definitions for vanilla-tilt 1.7.0
// Extended Type definitions for vanilla-tilt 1.8.1
// Project: https://github.com/micku7zu/vanilla-tilt.js
// Definitions by: Livio Brunner <https://github.com/BrunnerLivio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@ -43,13 +43,17 @@ export interface TiltOptions {
*/
transition?: boolean;
/**
* What axis should be disabled. Can be X or Y.
* What axis should be enabled. Can be "x" or "y".
*/
axis?: null | "x" | "y";
/**
* If the tilt effect has to be reset on exit.
*/
reset?: boolean;
/**
* Whether the exit reset will go to [0,0] (default) or [startX, startY].
*/
"reset-to-start"?: boolean;
/**
* Easing on enter/exit.
*/