vue-unwrap-element
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

unwrap-element (TypeScript)

npm downloads License

Easy solve problem of popup scroll freeze on mobile.

Motivation

The mobile popup has a page scrolling problem because the scrolling is not in the body itself. This module expands the element and hides everything around it, as like the element becomes the page itself and removes the page scrolling problem.

How to use it (few variants)

As script in browser

Add script

<script src=".../dist/unwrap-element.js"></script>

Use it

<div id="targetElement">Unwrap Test</div>

<script>
    const destroyUnwrap = unwrapElement('#targetElement');
    // TargetElement should place on all page
    // To revert all to previous state call destroyUnwrap();
    setTimeout(() => destroyUnwrap(), 5000);
</script>

As imported module

import unwrapElement from "unwrap-element";

const nodeOrSelector = '#targetElement';

/**
 * nodeOrSelector can be:
 * 1) #id
 * 2) .class
 * 3) domNode
 */

const destroyUnwrap = unwrapElement(nodeOrSelector);

// To revert all to previous state call destroyUnwrap();
setTimeout(() => destroyUnwrap(), 5000);

Api reference

const destroyUnwrap = unwrapElement(nodeOrSelector, {
  bypassSelectorsOrNodes: ['.class', '#id', domNode], // Optional
  beforeDestroy: async () => {}, // Optional, if returned false - prevent destroy
  beforeRestoreScroll: async () => {}, // Optional, if returned false - prevent restore scroll
  afterDestroy: async () => {}, // Optional
  
});

License

MIT License

Copyright (c) Igor Pylypenko

Readme

Keywords

none

Package Sidebar

Install

npm i vue-unwrap-element

Weekly Downloads

212

Version

2.0.6

License

ISC

Unpacked Size

15.8 kB

Total Files

27

Last publish

Collaborators

  • dryymoon