# ease-popup

> a simple, convenient and useful javascript plugin for popup

Latest version **1.2.2** (published 2024-03-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install ease-popup
pnpm add ease-popup
yarn add ease-popup
bun add ease-popup
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2024-03-24 |
| First published | 2024-03-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 45.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | wzcoding |
| Maintainers | wzcoding |
| Keywords | popup, e-popup, popup-plugin, popup-component, tooltip, dialog |

## Links

- npm: https://www.npmjs.com/package/ease-popup
- Repository: https://github.com/wzCoding/ease-popup
- Homepage: https://github.com/wzCoding/ease-popup#readme
- Issues: https://github.com/wzCoding/ease-popup/issues
- npm.io page: https://npm.io/package/ease-popup

## Dependencies (2)

- [core-js](https://npm.io/package/core-js.md) ^3.36.0
- [@floating-ui/dom](https://npm.io/package/@floating-ui/dom.md) ^1.6.3

## Alternatives

- [react-native-root-siblings](https://npm.io/package/react-native-root-siblings.md) — 102.9K weekly downloads
- [post-robot](https://npm.io/package/post-robot.md) — 93.7K weekly downloads
- [@praxisui/dialog](https://npm.io/package/@praxisui/dialog.md) — 2.0K weekly downloads
- [easy-toggle-state](https://npm.io/package/easy-toggle-state.md) — 350 weekly downloads
- [ngx-lightbox-evp](https://npm.io/package/ngx-lightbox-evp.md) — 19 weekly downloads

## Recent versions

- 1.2.2 (latest) — 2024-03-24
- 1.2.1 — 2024-03-23
- 1.2.0 — 2024-03-22
- 1.1.9 — 2024-03-21
- 1.1.8 — 2024-03-20
- 1.1.7 — 2024-03-20
- 1.1.6 — 2024-03-20
- 1.1.5 — 2024-03-20
- 1.1.4 — 2024-03-20
- 1.1.3 — 2024-03-20
- 1.1.2 — 2024-03-20
- 1.1.1 — 2024-03-20
- 1.1.0 — 2024-03-19
- 1.0.9 — 2024-03-19
- 1.0.8 — 2024-03-19
- … 8 more at https://npm.io/package/ease-popup/versions

## README

# ease-popup
一个简单、方便、有用的 JavaScript 弹窗插件，基于 `floating-ui` 制作

## 文档
[点击查看文档](https://wzcoding.github.io/ease-popup/)

## 介绍
1. 这是一个简单、方便、好用的 js 弹窗插件，可以作为 tooltip 提示框、dialog 对话框等使用，也可以在此基础上自由封装改造。
2. 本弹窗插件基于 [floating-ui] 制作，弹窗可选位置齐全，功能相对完善，配置简单。
3. 弹窗使用 html5 `dialog` 元素生成，也支持使用 `div` 元素，兼容性较好。
4. 弹窗只提供基础样式，不用引入额外的 CSS 文件，想要其他样式可以自行定义编写。
   
## 安装
推荐使用 npm包 的方式进行安装
```
npm install ease-popup
```
或者也可以使用 `<script>` 标签引入

```
<script src="https://cdn.jsdelivr.net/gh/wzCoding/ease-popup@v1.2.0/dist/EasePopup.min.js"></script>
```

## 使用
```
import EasePopup from 'ease-popup'

// 或者

const EasePopup = require('ease-popup')
```

## 示例
以下是插件的简单使用方式

HTML 部分
// 弹窗容器也可以换成 `<dialog>` 元素
```html

<button id="popupBtn">点我</button>
<div class="ease-popup"> 
    <div class="ease-popup-content">这是一个弹窗</div>
</div>

```
JavaScript 部分
```js

const btn = document.getElementById('popupBtn')
const popup = document.querySelector('.ease-popup')


const instance = new EasePopup({
    "target":btn,
    "popup":popup,
    "direction":"top",
})

instance.update() // 更新弹窗配置
instance.show() // 显示弹窗
instance.showModal() // 显示弹窗并显示layer层
instance.hide() // 隐藏弹窗（隐藏layer层）
instance.destroy() // 销毁弹窗

```
## options选项参数

| 参数名         | 类型           | 默认值    | 说明                                                                                                           |
| -------------- | -------------- | --------- | -------------------------------------------------------------------------------------------------------------- |
| target         | Element String | null      | 弹窗触发元素                                                                                                   |
| popup          | Element String | null      | 弹窗元素                                                                                                       |
| direction      | String         | 'bottom'  | 弹窗popup显示的方向，根据placement参数的不同而变化                                                             |
| placement      | String         | 'outside' | 弹窗popup的放置部位（位于目标元素的外部或者内部）                                                              |
| width          | Number String  | 'auto'    | 弹窗宽度                                                                                                       |
| content        | String         | ' '       | 弹窗popup中要显示的内容                                                                                        |
| container      | String Object  | 'body'    | 弹窗触发元素target所在的容器，确定容器可以防止popup溢出边界                                                    |
| theme          | String Object  | 'light'   | 弹窗popup的主题（设置文字与背景色，默认提供 'light' 与 'dark' 两种主题，也可以传入{background:'',color:''}对象 |
| targetGap      | Number         | 15        | 弹窗popup与目标元素（触发元素）的间距                                                                          |
| boundryGap     | Number         | 5         | 弹窗popup与容器边缘的间距                                                                                      |
| offset         | Array          | [0,0]     | 弹窗popup相对所在位置的偏移量 [x,y]                                                                            |
| needArrow      | Boolean        | true      | 弹窗popup是否需要小箭头                                                                                        |
| selfClick      | Boolean        | true      | 弹窗popup自身是否可以点击                                                                                      |
| closeByOutSide | Boolean        | true      | 是否在点击弹窗popup以外的区域时关闭popup                                                                       |
| singleOpen     | Boolean        | true      | 是否同时只打开一个弹窗popup                                                                                    |
| fullScreen     | Boolean        | false     | layer层是否全屏                                                                                                |
| onShow          | Function        | null      | 弹窗popup显示时的回调函数                                                                                    |
| onHide          | Function        | null      | 弹窗popup隐藏时的回调函数                                                                                    |
| onDestroy      | Function        | null      | 弹窗popup销毁时的回调函数                                                                                    |

插件只提供了基础的弹窗展示、隐藏、销毁功能，弹窗的触发方式、弹窗内部结构等可由使用者自行定义。

[floating-ui]:https://floating-ui.com/

---
_Source: https://npm.io/package/ease-popup · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
