mirror of
https://github.com/micku7zu/vanilla-tilt.js
synced 2024-06-01 21:32:11 +02:00
Compare commits
23 commits
Author | SHA1 | Date | |
---|---|---|---|
48f4ee931d | |||
967ab1accf | |||
f4a557955d | |||
7a179baa43 | |||
bfe0c75eb5 | |||
2a1f867ec1 | |||
042c3eac64 | |||
0c73694cb8 | |||
475fa30d50 | |||
ffc28a5bab | |||
7f606cd52d | |||
e80bf21faa | |||
82792cbc9e | |||
29d586ce5b | |||
6315937c6e | |||
61559a399a | |||
2ee96e937f | |||
f6b73dac54 | |||
43ca5c53cf | |||
cb1f298d83 | |||
66f7af8fa1 | |||
ebcf46cec4 | |||
20f9edad9e |
|
@ -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)
|
||||
|
|
15
README.md
15
README.md
|
@ -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
|
||||
|
|
64
dist/vanilla-tilt.babel.js
vendored
64
dist/vanilla-tilt.babel.js
vendored
|
@ -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,
|
||||
|
|
2
dist/vanilla-tilt.babel.min.js
vendored
2
dist/vanilla-tilt.babel.min.js
vendored
File diff suppressed because one or more lines are too long
71
dist/vanilla-tilt.js
vendored
71
dist/vanilla-tilt.js
vendored
|
@ -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,
|
||||
|
|
2
dist/vanilla-tilt.min.js
vendored
2
dist/vanilla-tilt.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
7263
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
8
vanilla-tilt.d.ts
vendored
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue