提交 0aebd1a7 编写于 作者: K Kamran Ahmed

Add docs and allow modifying padding

上级 fe79342b
...@@ -9,7 +9,10 @@ ...@@ -9,7 +9,10 @@
"no-plusplus": "off", "no-plusplus": "off",
"no-cond-assign": "off", "no-cond-assign": "off",
"func-names": "off", "func-names": "off",
"no-param-reassign": ["off"], "no-param-reassign": [
"max-len": "off" "off"
],
"max-len": "off",
"no-multi-spaces": "off"
} }
} }
\ No newline at end of file
## spotlight-js
> Allows highlighting any element, adding feature introduction, adding hints
## Highlighting Single Elements
```javascript
const spotlight = new Spotlight({
opacity: 0.7, // opacity for the background
padding: 5, // padding around the element
});
spotlight.highlight('#some-element');
spotlight.clear();
```
\ No newline at end of file
...@@ -5,15 +5,17 @@ import Position from './position'; ...@@ -5,15 +5,17 @@ import Position from './position';
* cutting out the visible part, animating between the sections etc * cutting out the visible part, animating between the sections etc
*/ */
export default class Overlay { export default class Overlay {
constructor({ opacity = 0.75 }) { constructor({ opacity = 0.75, padding = 5 }) {
this.opacity = opacity; this.opacity = opacity; // Fixed opacity for the layover
this.overlayAlpha = 0; this.padding = padding; // Padding around the highlighted item
this.positionToHighlight = new Position({});
this.highlightedPosition = new Position({}); this.overlayAlpha = 0; // Is used to animate the layover
this.redrawAnimation = null; this.positionToHighlight = new Position({}); // position at which layover is to be patched at
this.highlightedElement = null; this.highlightedPosition = new Position({}); // position at which layover is patched currently
this.redrawAnimation = null; // used to cancel the redraw animation
this.highlightedElement = null; // currently highlighted dom element (instance of Element)
this.draw = this.draw.bind(this); this.draw = this.draw.bind(this); // To pass the context of class, as it is to be used in redraw animation callback
this.window = window; this.window = window;
this.document = document; this.document = document;
...@@ -101,10 +103,10 @@ export default class Overlay { ...@@ -101,10 +103,10 @@ export default class Overlay {
// Remove the cloak from the position to highlight // Remove the cloak from the position to highlight
this.removeCloak({ this.removeCloak({
posX: this.highlightedPosition.left - window.scrollX - 5, posX: this.highlightedPosition.left - window.scrollX - this.padding,
posY: this.highlightedPosition.top - window.scrollY - 5, posY: this.highlightedPosition.top - window.scrollY - this.padding,
width: (this.highlightedPosition.right - this.highlightedPosition.left) + (5 * 2), width: (this.highlightedPosition.right - this.highlightedPosition.left) + (this.padding * 2),
height: (this.highlightedPosition.bottom - this.highlightedPosition.top) + (5 * 2), height: (this.highlightedPosition.bottom - this.highlightedPosition.top) + (this.padding * 2),
}); });
if (canHighlight) { if (canHighlight) {
......
...@@ -6,8 +6,11 @@ import './polyfill'; ...@@ -6,8 +6,11 @@ import './polyfill';
* Plugin class that drives the plugin * Plugin class that drives the plugin
*/ */
export default class Sholo { export default class Sholo {
constructor({ opacity = 0.75 } = {}) { constructor({ opacity = 0.75, padding = 5 } = {}) {
this.overlay = new Overlay({ opacity }); this.overlay = new Overlay({
opacity,
padding,
});
} }
highlight(selector) { highlight(selector) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册