Allow disabling highlight

This commit is contained in:
Kamran Ahmed
2018-03-04 19:32:19 +01:00
parent bb8be8c6c4
commit 31d8a1a8d8
3 changed files with 26 additions and 6 deletions
+12 -3
View File
@@ -5,9 +5,14 @@ import Position from './position';
* cutting out the visible part, animating between the sections etc
*/
export default class Overlay {
constructor({ opacity = 0.75, padding = 5 }) {
constructor({
opacity = 0.75,
padding = 5,
animate = true,
}) {
this.opacity = opacity; // Fixed opacity for the layover
this.padding = padding; // Padding around the highlighted item
this.animate = animate; // Should animate between the transitions
this.overlayAlpha = 0; // Is used to animate the layover
this.positionToHighlight = new Position({}); // position at which layover is to be patched at
@@ -56,7 +61,7 @@ export default class Overlay {
// If animation is not required then set the last path to be same
// as the current path so that there is no easing towards it
if (!animate) {
if (!this.animate || !animate) {
this.highlightedPosition = this.positionToHighlight;
}
@@ -111,7 +116,11 @@ export default class Overlay {
if (canHighlight) {
// Fade the overlay in if we can highlight
this.overlayAlpha += (this.opacity - this.overlayAlpha) * 0.08;
if (!this.animate) {
this.overlayAlpha = this.opacity;
} else {
this.overlayAlpha += (this.opacity - this.overlayAlpha) * 0.08;
}
} else {
// otherwise fade out
this.overlayAlpha = Math.max((this.overlayAlpha * 0.85) - 0.02, 0);
+11 -2
View File
@@ -6,8 +6,17 @@ import './polyfill';
* Plugin class that drives the plugin
*/
export default class Sholo {
constructor({ opacity = 0.75, padding = 5 } = {}) {
this.overlay = new Overlay({ opacity, padding });
constructor({
opacity = 0.75,
padding = 5,
animate = true,
} = {}) {
this.overlay = new Overlay({
opacity,
padding,
animate,
});
this.document = document;
this.window = window;
+3 -1
View File
@@ -50,7 +50,9 @@
'.section__examples'
];
const sholo = new Sholo();
const sholo = new Sholo({
animate: false
});
nodesToSelect.forEach((nodeToSelect, index) => {
window.setTimeout(() => {