SweetAlert2
-----------
[![Build Status](https://travis-ci.org/limonte/sweetalert2.svg?branch=master)](https://travis-ci.org/limonte/sweetalert2)
[![Version](https://img.shields.io/npm/v/sweetalert2.svg)](https://www.npmjs.com/package/sweetalert2)
[![Standard - JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
[![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/limonte/sweetalert2.svg)](http://isitmaintained.com/project/limonte/sweetalert2 "Average time to resolve an issue")
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sweetalert2/Lobby)
[![Support me on Patreon](http://ionicabizau.github.io/badges/patreon.svg)](https://www.patreon.com/limonte)
[![PayPal Donate](http://ionicabizau.github.io/badges/paypal.svg)](https://www.paypal.me/limonte/5eur)
A beautiful, responsive, customizable, accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
What's the difference between SweetAlert and SweetAlert2?
---------------------------------------------------------
- [Reason of creating this fork is inactivity of original SweetAlert plugin](http://stackoverflow.com/a/27842854/1331425)
- [SweetAlert to SweetAlert2 migration guide](https://github.com/limonte/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2)
---
[See SweetAlert2 in action!](https://limonte.github.io/sweetalert2/)
<img src="https://raw.github.com/limonte/sweetalert2/master/assets/sweetalert2.gif" width="686">
Installation
------------
```bash
npm install --save sweetalert2
```
Or:
```bash
bower install --save sweetalert2
```
Or download from CDN: [cdnjs.com/limonte-sweetalert2](https://cdnjs.com/libraries/limonte-sweetalert2)
Usage
-----
```html
<script src="bower_components/sweetalert2/dist/sweetalert2.min.js"></script>
<link rel="stylesheet" type="text/css" href="bower_components/sweetalert2/dist/sweetalert2.min.css">
<!-- Include a polyfill for ES6 Promises (optional) for IE11, UC Browser and Android browser support -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/core.js"></script>
```
Or:
```js
// ES6 Modules or TypeScript
import swal from 'sweetalert2'
// CommonJS
const swal = require('sweetalert2')
```
Please note that TypeScript is supported, so you don't have to install a third-party declaration file.
Examples
--------
The most basic message:
```js
swal('Hello world!')
```
A message signaling an error:
```js
swal('Oops...', 'Something went wrong!', 'error')
```
Handling the result of SweetAlert2 modal:
```js
swal({
title: 'Are you sure?',
text: 'You will not be able to recover this imaginary file!',
type: 'warning',
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, keep it'
}).then(function() {
swal(
'Deleted!',
'Your imaginary file has been deleted.',
'success'
)
}, function(dismiss) {
// dismiss can be 'overlay', 'cancel', 'close', 'esc', 'timer'
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
```
[View more examples](https://limonte.github.io/sweetalert2/)
Handling Dismissals
-------------------
When an alert is dismissed by the user, the Promise returned by `swal()` will reject with a string documenting the reason it was dismissed:
| String | Description | Related configuration |
| ----------- | ------------------------------------------------------- | --------------------- |
| `'overlay'` | The user clicked the overlay. | `allowOutsideClick` |
| `'cancel'` | The user clicked the cancel button. | `showCancelButton` |
| `'close'` | The user clicked the close button. | `showCloseButton` |
| `'esc'` | The user pressed the <kbd>Esc</kbd> key. | `allowEscapeKey` |
| `'timer'` | The timer ran out, and the alert closed automatically. | `timer` |
If rejections are not handled, it will be logged as an error. To avoid this, add a rejection handler to the Promise. Alternatively, you can use `.catch(swal.noop)` as a quick way to simply suppress the errors:
```js
swal(...)
.catch(swal.noop)
```
Modal Types
-----------
| `success` | `error` | `warning` | `info` | `question` |
| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| ![](https://raw.github.com/limonte/sweetalert2/master/assets/swal2-success.png) | ![](https://raw.github.com/limonte/sweetalert2/master/assets/swal2-error.png) | ![](https://raw.github.com/limonte/sweetalert2/master/assets/swal2-warning.png) | ![](https://raw.github.com/limonte/sweetalert2/master/assets/swal2-info.png) | ![](https://raw.github.com/limonte/sweetalert2/master/assets/swal2-question.png) |
Configuration
-------------
| Argument | Default value | Description |
| ------------------------ | -------------------- | ----------- |
| `title` | `null` | The title of the modal, as HTML. It can either be added to the object under the key "title" or passed as the first parameter of the function. |
| `titleText` | `null` | The title of the modal, as text. Useful to avoid HTML injection. |
| `text` | `null` | A description for the modal. It can either be added to the object under the key "text" or passed as the second parameter of the function. |
| `html` | `null` | A HTML description for the modal. If `text` and `html` parameters are provided in the same time, "text" will be used. |
| `type` | `null` | The type of the modal. SweetAlert2 comes with [5 built-in types](#modal-types) which will show a corresponding icon animation: `warning`, `error`, `success`, `info` and `question`. It can either be put in the array under the key `type` or passed as the third parameter of the function. |
| `target` | `'body'` | The container element for adding modal into. |
| `input` | `null` | Input field type, can be `'text'`, `'email'`, `'password'`, `'number'`, `'tel'`, `'range'`, `'textarea'`, `'select'`, `'radio'`, `'checkbox'`, `'file'` and `'url'`. |
| `width` | `'500px'` | Modal window width, including paddings (`box-sizing: border-box`). Can be in `px` or `%`. |
| `padding` | `20` | Modal window padding. |
| `background` | `'#fff'` | Modal window background (CSS `background` property). |
| `customClass` | `null` | A custom CSS class for the modal. |
| `timer` | `null` | Auto close timer of the modal. Set in ms (milliseconds). |
| `animation` | `true` | If set to `false`, modal CSS animation will be disabled. |
| `allowOutsideClick` | `true` | If set to `false`, the user can't dismiss the modal by clicking outside it. |
| `allowEscapeKey` | `true` | If set to `false`, the user can't dismiss the modal by pressing t
没有合适的资源?快使用搜索试试~ 我知道了~
sweetalear2弹窗插件 官方原码和打包文件js,css打包文件
共49个文件
js:12个
png:11个
json:4个
需积分: 13 6 下载量 107 浏览量
2017-09-15
18:18:35
上传
评论
收藏 264KB ZIP 举报
温馨提示
官方原码和打包文件js,css打包文件在sweetalert2-master\dist里面,配套齐全,拎包开发,导入即可进行弹窗使用
资源推荐
资源详情
资源评论
收起资源包目录
sweetalert2-master.zip (49个子文件)
sweetalert2-master
.gemini.yml 245B
index.html 61KB
.github
CONTRIBUTING.md 698B
CODE_OF_CONDUCT.md 1KB
qunit
index.html 627B
tests.js 19KB
bower.json 1KB
src
utils
classes.js 758B
utils.js 811B
dom.js 10KB
params.js 1KB
colors.scss 971B
sweetalert2.scss 13KB
sweetalert2.js 36KB
.babelrc 164B
sweetalert2.d.ts 16KB
.travis.yml 466B
gulpfile.js 2KB
config
utils.js 1KB
banner.js 195B
LICENSE 1KB
assets
swal2-success.png 3KB
paypal.png 6KB
favicon.png 2KB
swal2-question.png 3KB
favicon.ico 1KB
vs_icon.png 4KB
patreon.png 8KB
apple-touch-icon.png 3KB
swal2-error.png 3KB
swal2-warning.png 3KB
example.css 9KB
bootstrap4-buttons.css 15KB
example.scss 9KB
vs_icon@2x.png 8KB
sweetalert2.gif 84KB
swal2-info.png 5KB
README.md 19KB
dist
sweetalert2.min.js 24KB
sweetalert2.js 54KB
sweetalert2.common.js 53KB
sweetalert2.css 19KB
sweetalert2.min.css 14KB
testem.json 276B
.sass-lint.yml 189B
.editorconfig 193B
.gitignore 35B
package-lock.json 173KB
package.json 2KB
共 49 条
- 1
资源评论
奔跑的叮叮猫
- 粉丝: 6
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功