element-overlap
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "element-overlap", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Trigger an callback when two DOM elements overlap", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# element-overlap | ||
Trigger an callback when two DOM elements overlap. | ||
Trigger an callback when two DOM elements overlap. | ||
## Usage Example | ||
```js | ||
// For ES6: | ||
import listenForOverlap from 'element-overlap'; | ||
// ...or for CommonJS: | ||
var listenForOverlap = require('element-overlap').listenForOverlap; | ||
listenForOverlap( | ||
'#element1', '#element2', | ||
function() { | ||
alert('The elements have overlapped!'); | ||
} | ||
); | ||
``` | ||
## API and Options | ||
### `void listenForOverlap(element1, element2, callback, options))` | ||
The main method to set up a listener for the overlap. Will call `callback` when the elements are | ||
overlapping according to the value `options.requiredIntersection`. | ||
#### Arguments | ||
##### `string` or `HTMLElement` :: **`element1`** - required | ||
The first of the two elements to compare. This can either be a [CSS selector string](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_Started/Selectors) | ||
or a reference to a DOM element (eg: the result of `getElementById` or `querySelector`) |
@@ -33,2 +33,3 @@ import isString from 'is-string'; | ||
* @property {overlapTypes} requiredIntersection | ||
* @property {*} callbackData | ||
*/ | ||
@@ -82,7 +83,7 @@ | ||
case overlapTypes.intersect: | ||
callback(); | ||
callback(options.callbackData); | ||
break; | ||
case overlapTypes.contain: | ||
if (doesElementContainElement(element2, element1)) { | ||
callback(); | ||
callback(options.callbackData); | ||
} | ||
@@ -92,3 +93,3 @@ break; | ||
if (doesElementContainElement(element1, element2)) { | ||
callback(); | ||
callback(options.callbackData); | ||
} | ||
@@ -95,0 +96,0 @@ break; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67538
1686
33