├── .gitignore ├── LICENSE ├── README.md ├── README2.md ├── alert.html ├── confirm.html ├── js └── component.js └── toast.html /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | .idea -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 零度逍遥 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # popup 2 | 最小巧的移动端弹窗组件,toast、alert、confirm,使用原生js,不依赖任何类库,不需要引入任何css文件,只有一个js文件 3 | 4 | **组件设计为单例模式,在一个打开状态,再次打开另一个,会自动关闭上一个** 5 | 6 | ## 1. toast 7 | ``` 8 | let toast = new ToastClass(); 9 | ``` 10 | 11 | - 方法 12 | 13 | 方法名 | 说明 14 | :----: | :----: 15 | show | 打开方法 16 | hide | 关闭方法 17 | onShow | 打开时回调(全局) 18 | onHide | 关闭时回调(全局) 19 | 20 | ### toast打开方法 21 | ``` 22 | toast.show(options) 23 | ``` 24 | 25 | - options 26 | 27 | | 参数 | 类型 | 默认值 | 说明| 28 | | :----: | :----: | :----: |:----: | 29 | | text | String | 正在加载 | 展示文本| 30 | | loading | Boolean | false | 是否展示loading图标| 31 | | duration | Number | 无 | 持续时间(ms)| 32 | | onShow | Function | 无 | 打开时回调| 33 | | onHide | Function | 无 | 关闭时回调| 34 | 35 | - 示例 (可参考 [toast.html](https://github.com/lingdublog/popup/blob/master/toast.html) ) 36 | ``` 37 | toast.show({ 38 | text: '正在加载', 39 | duration: 2000, 40 | onShow: function(){ 41 | console.log('打开了toast') 42 | } 43 | }) 44 | ``` 45 | 46 | ### toast关闭方法 47 | ``` 48 | toast.hide() 49 | ``` 50 | 51 | 52 | ## 2. alert 53 | ``` 54 | let alert = new AlertClass(); 55 | ``` 56 | 57 | - 方法 58 | 59 | 方法名 | 说明 60 | :----: | :----: 61 | show | 打开方法 62 | hide | 关闭方法 63 | onShow | 打开时回调(全局) 64 | onHide | 关闭时回调(全局) 65 | 66 | ### alert打开方法 67 | ``` 68 | alert.show(options) 69 | ``` 70 | 71 | - options 72 | 73 | | 参数 | 类型 | 默认值 | 说明| 74 | | :----: | :----: | :----: |:----: | 75 | | title | String | 无 | 标题| 76 | | content | String | 无 | 内容| 77 | | btnText | String | 确定 | 按钮文本| 78 | | onShow | Function | 无 | 打开时回调| 79 | | onHide | Function | 无 | 关闭时回调| 80 | 81 | - 示例 (可参考 [alert.html](https://github.com/lingdublog/popup/blob/master/alert.html) ) 82 | ``` 83 | alert.show({ 84 | title: '提示标题', 85 | content: '提示内容', 86 | onShow: function(){ 87 | console.log('打开了alert') 88 | } 89 | }) 90 | ``` 91 | 92 | ### alert关闭方法 93 | ``` 94 | alert.hide() 95 | ``` 96 | 97 | 98 | ## 3. confirm 99 | ``` 100 | let confirm = new ConfirmClass(); 101 | ``` 102 | 103 | - 方法 104 | 105 | 方法名 | 说明 106 | :----: | :----: 107 | show | 打开方法 108 | hide | 关闭方法 109 | onShow | 打开时回调(全局) 110 | onHide | 关闭时回调(全局) 111 | 112 | ### confirm打开方法 113 | ``` 114 | confirm.show(options) 115 | ``` 116 | 117 | - options 118 | 119 | | 参数 | 类型 | 默认值 | 说明| 120 | | :----: | :----: | :----: |:----: | 121 | | title | String | 无 | 标题| 122 | | content | String | 无 | 内容| 123 | | btns | Array | 见下方btns | 按钮文本/css类| 124 | | onShow | Function | 无 | 打开时回调| 125 | | onHide | Function | 无 | 关闭时回调| 126 | 127 | - btns 默认值:[{text: '确定', class: 'confirm'}, {text: '取消', class: 'cancel'}] 128 | 129 | | 参数 | 类型 | 默认值 | 说明| 130 | | :----: | :----: | :----: |:----: | 131 | | text | String | 确定、取消 | 按钮文本| 132 | | class | String | confirm、cancel | 按钮css类| 133 | | callback | Function | 无 | 按钮点击回调| 134 | 135 | - 示例 (可参考 [confirm.html](https://github.com/lingdublog/popup/blob/master/confirm.html) ) 136 | ``` 137 | confirm.show({ 138 | title: '提示标题', 139 | content: '提示内容', 140 | btns: [{ 141 | callback: function(instance){ 142 | instance.close = false; 143 | console.log('点击了确定按钮,但不会关闭弹窗'); 144 | } 145 | }, { 146 | text: '不需要', 147 | callback: function(){ 148 | console.log('点击了不需要按钮'); 149 | } 150 | }], 151 | onShow: function(){ 152 | console.log('打开了confirm') 153 | } 154 | }) 155 | ``` 156 | 157 | ### confirm关闭方法 158 | ``` 159 | confirm.hide() 160 | ``` 161 | 162 | -------------------------------------------------------------------------------- /README2.md: -------------------------------------------------------------------------------- 1 | # popup 2 | 最小巧的移动端弹窗组件,toast、alert、confirm,使用原生js,不依赖任何类库,不需要引入任何css文件,只有一个js文件 3 | 4 | **组件设计为单例模式,在一个打开状态,再次打开另一个,会自动关闭上一个** 5 | 6 | ## 1. toast 7 | ``` 8 | let toast = new ToastClass(); 9 | ``` 10 | 11 | - 方法 12 | 13 | 方法名 | 说明 14 | :----: | :----: 15 | show | 打开方法 16 | hide | 关闭方法 17 | onShow | 打开时回调(全局) 18 | onHide | 关闭时回调(全局) 19 | 20 | ### toast打开方法 21 | ``` 22 | toast.show(options) 23 | ``` 24 | 25 | - options 26 | 27 | | 参数 | 类型 | 默认值 | 说明| 28 | | :----: | :----: | :----: |:----: | 29 | | text | String | 正在加载 | 展示文本| 30 | | loading | Boolean | false | 是否展示loading图标| 31 | | duration | Number | 无 | 持续时间(ms)| 32 | | onShow | Function | 无 | 打开时回调| 33 | | onHide | Function | 无 | 关闭时回调| 34 | 35 | - 示例 (可参考 [toast.html](https://github.com/lingdublog/popup/blob/master/toast.html) ) 36 | ``` 37 | toast.show({ 38 | text: '正在加载', 39 | duration: 2000, 40 | onShow: function(){ 41 | console.log('打开了toast') 42 | } 43 | }) 44 | ``` 45 | 46 | ### toast关闭方法 47 | ``` 48 | toast.hide() 49 | ``` 50 | 51 | ### 在线示例 52 | [toast展示](http://works.lingdublog.cc/popup/toast.html) 53 | 54 | 55 | ## 2. alert 56 | ``` 57 | let alert = new AlertClass(); 58 | ``` 59 | 60 | - 方法 61 | 62 | 方法名 | 说明 63 | :----: | :----: 64 | show | 打开方法 65 | hide | 关闭方法 66 | onShow | 打开时回调(全局) 67 | onHide | 关闭时回调(全局) 68 | 69 | ### alert打开方法 70 | ``` 71 | alert.show(options) 72 | ``` 73 | 74 | - options 75 | 76 | | 参数 | 类型 | 默认值 | 说明| 77 | | :----: | :----: | :----: |:----: | 78 | | title | String | 无 | 标题| 79 | | content | String | 无 | 内容| 80 | | btnText | String | 确定 | 按钮文本| 81 | | onShow | Function | 无 | 打开时回调| 82 | | onHide | Function | 无 | 关闭时回调| 83 | 84 | - 示例 (可参考 [alert.html](https://github.com/lingdublog/popup/blob/master/alert.html) ) 85 | ``` 86 | alert.show({ 87 | title: '提示标题', 88 | content: '提示内容', 89 | onShow: function(){ 90 | console.log('打开了alert') 91 | } 92 | }) 93 | ``` 94 | 95 | ### alert关闭方法 96 | ``` 97 | alert.hide() 98 | ``` 99 | 100 | ### 在线示例 101 | [alert展示](http://works.lingdublog.cc/popup/alert.html) 102 | 103 | 104 | ## 3. confirm 105 | ``` 106 | let confirm = new ConfirmClass(); 107 | ``` 108 | 109 | - 方法 110 | 111 | 方法名 | 说明 112 | :----: | :----: 113 | show | 打开方法 114 | hide | 关闭方法 115 | onShow | 打开时回调(全局) 116 | onHide | 关闭时回调(全局) 117 | 118 | ### confirm打开方法 119 | ``` 120 | confirm.show(options) 121 | ``` 122 | 123 | - options 124 | 125 | | 参数 | 类型 | 默认值 | 说明| 126 | | :----: | :----: | :----: |:----: | 127 | | title | String | 无 | 标题| 128 | | content | String | 无 | 内容| 129 | | btns | Array | 见下方btns | 按钮文本/css类| 130 | | onShow | Function | 无 | 打开时回调| 131 | | onHide | Function | 无 | 关闭时回调| 132 | 133 | - btns 默认值:[{text: '确定', class: 'confirm'}, {text: '取消', class: 'cancel'}] 134 | 135 | | 参数 | 类型 | 默认值 | 说明| 136 | | :----: | :----: | :----: |:----: | 137 | | text | String | 确定、取消 | 按钮文本| 138 | | class | String | confirm、cancel | 按钮css类| 139 | | callback | Function | 无 | 按钮点击回调| 140 | 141 | - 示例 (可参考 [confirm.html](https://github.com/lingdublog/popup/blob/master/confirm.html) ) 142 | ``` 143 | confirm.show({ 144 | title: '提示标题', 145 | content: '提示内容', 146 | btns: [{ 147 | callback: function(instance){ 148 | instance.close = false; 149 | console.log('点击了确定按钮,但不会关闭弹窗'); 150 | } 151 | }, { 152 | text: '不需要', 153 | callback: function(){ 154 | console.log('点击了不需要按钮'); 155 | } 156 | }], 157 | onShow: function(){ 158 | console.log('打开了confirm') 159 | } 160 | }) 161 | ``` 162 | 163 | ### confirm关闭方法 164 | ``` 165 | confirm.hide() 166 | ``` 167 | 168 | ### 在线示例 169 | [confirm展示](http://works.lingdublog.cc/popup/confirm.html) 170 | -------------------------------------------------------------------------------- /alert.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |