Sweet Alert
http://www.dglives.com/demo/sweetalert-master/example/
Sweet Alert
A beautiful replacement for Javascript's "Alert"
So... What does it do?
Here’s a comparison of a standard error message. The first one uses the built-in alert-function, while the second is using sweetAlert.
Normal alert
Code:
alert("Oops... Something went wrong!");
Sweet Alert
Code:
sweetAlert("Oops...", "Something went wrong!", "error");
Pretty cool huh? SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. It's even highly customizeable, as you can see below!
More examples
In these examples, we're using the shorthand function swal to call sweetAlert.
A basic message
swal("Here's a message!")
swal({
title: "Sweet!",
text: "Here's a custom image.",
imageUrl: "images/thumbs-up.jpg"
});
Download & install
Method 1: Install through bower:
$ bower install sweetalert
Method 2: Download the sweetAlert CSS and JavaScript files.
Initialize the plugin by referencing the necessary files:
<script src="lib/sweet-alert.min.js"></script>
<link rel="stylesheet" type="text/css" href="lib/sweet-alert.css">Call the sweetAlert-function after the page has loaded
swal({
title: "Error!",
text: "Here's my error message!",
type: "error",
confirmButtonText: "Cool"
});
Configuration
Here are the keys that you can use if you pass an object into sweetAlert:
| Argument | Default value | Description |
|---|---|---|
| title | null (required) | The title of the modal. It can either be added to the object under the key "title" or passed as the first parameter of the function. |
| 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. |
| type | null | The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". It can either be put in the array under the key "type" or passed as the third parameter of the function. |
| allowOutsideClick | false | If set to true, the user can dismiss the modal by clicking outside it. |
| showCancelButton | false | If set to true, a "Cancel"-button will be shown, which the user can click on to dismiss the modal. |
| confirmButtonText | "OK" | Use this to change the text on the "Confirm"-button. If showCancelButton is set as true, the confirm button will automatically show "Confirm" instead of "OK". |
| confirmButtonColor | "#AEDEF4" | Use this to change the background color of the "Confirm"-button (must be a HEX value). |
| cancelButtonText | "Cancel" | Use this to change the text on the "Cancel"-button. |
| closeOnConfirm | true | Set to false if you want the modal to stay open even if the user presses the "Confirm"-button. This is especially useful if the function attached to the "Confirm"-button is another SweetAlert. |
| imageUrl | null | Add a customized icon for the modal. Should contain a string with the path to the image. |
| imageSize | "80x80" | If imageUrl is set, you can specify imageSize to describes how big you want the icon to be in px. Pass in a string with two values separated by an "x". The first value is the width, the second is the height. |
Contribute
SweetAlert was created by Tristan Edwards, you can follow him on Twitter or Dribbble for updates and other cool projects!
Feel free to fork sweetAlert on GitHub if you have any features that you want to add!
TE • 2014
A title with a text under
swal("Here's a message!", "It's pretty, isn't it?")A success message!
swal("Good job!", "You clicked the button!", "success")A warning message, with a function attached to the "Confirm"-button...
swal({
title: "Are you sure?",
text: "Your will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
},
function(){
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});... and by passing a parameter, you can execute something else for "Cancel".
swal({
title: "Are you sure?",
text: "Your will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});A message with a custom icon
Sweet Alert的更多相关文章
- 漂亮的各种弹出框 sweet alert
Sweet Alert 是一个替代传统的 Alert 的提示效果.SweetAlert 自动居中对齐在页面中央,不管您使用的是台式电脑,手机或平板电脑看起来效果都很棒. 还带下拉 几种 动画效果 弹窗 ...
- 效果非常好的 Jquery弹出层插件 jQuery Sweet alert
介绍款交互性非常不错的jquery弹出层插件,支持消息提示.错误提示.确认框提示等. 交互式体验感非常不错,比如咱们现在体验非常不错的微信支付.支付宝等完成后的效果. 不过本插件至少支持IE9+ Jq ...
- 好看的dialog,sweet Alert Dialog 导入Android Studio
系统自带的dialog实在是丑到无法忍受.所以找到了一款比较好的第三方dialog. github 地址如下:https://github.com/pedant/sweet-alert-dialog ...
- SweetAlert – 替代 Alert 的漂亮的提示效果
Sweet Alert 是一个替代传统的 JavaScript Alert 的漂亮提示效果.SweetAlert 自动居中对齐在页面中央,不管您使用的是台式电脑,手机或平板电脑看起来效果都很棒.另外提 ...
- 基于jquery的响应式提示框SweetAlert
介绍款交互性非常不错的jquery弹出层插件,支持消息提示.错误提示.确认框提示等.交互式体验感非常不错,比如咱们现在体验非常不错的微信支付.支付宝等完成后的效果.不过本插件至少支持IE9+.使用方式 ...
- GitHub Top 100的Android开源库
摘要: 本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍, 至于排名完全是根据GitHub搜索Java语言选择「Best M... 本项目主要对目前 GitH ...
- android UI库
https://github.com/wasabeef/awesome-android-ui List of Android UI/UX Libraries A curated list of awe ...
- Android Studio插件
awesome-android-ui(UI范例库) https://github.com/wasabeef/awesome-android-ui/tree/master/pages LMBanners ...
- 关于abp中使用的sweetalert对话框组件的confirm确认对话框中的一个坑
今天修改了一个功能,限制删除用户,在删除的时候不满足条件的时候提示用户原因,使用的sweet alert组件. abp框架前端集成了sweet alert 对http请求的error做了全局处理,我在 ...
随机推荐
- 用python爬取QQ空间
好久没写博文了,最近捣鼓了一下python,好像有点上瘾了,感觉python比js厉害好多,但是接触不久,只看了<[大家网]Python基础教程(第2版)[www.TopSage.com]> ...
- yii2-basic后台管理功能开发之四:图片上传FileInput
我采用的是 kartik-v/yii2-widget-fileinput的文件上传插件,大家可以去github查看详细的安装方法和使用说明. 需求:上传图片+可以预览缩略图 在这里说说我碰到的问题:限 ...
- 版本控制简介,git使用----使用GitHub托管代码
关于版本控制: 很久以前,人们苦于对写过的代码进行版本的管理,经常过了一段时间想恢复原来写过的代码却又忘了不知道丢到哪儿去了,有的人用加上时间后缀来命名文件的方法,便于后期维护,但是这样做的麻烦也很大 ...
- CSS3支持box-flex弹性布局
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...
- PHP多条件搜索ShopNc实例
控制器部分代码: if (trim($_GET['keyword']) != '') { //echo $_GET['search_type']; exit(); switch ($_GET['sea ...
- Windows下配置nginx+php(wnmp)
第一部分:准备工作.(系统:Windows 8.1) 1.首先是下载软件. NGINX-1.3.8官网下载:http://nginx.org/en/download.html PHP5.4.8版本 ...
- [原创]WPF应用MediaPlayer播放声音断续、不全解决方案
1.检查扬声器和驱动程序. 测试方法:首先,应用Windows Media Player播放器播放,看是否有问题,如果有问题,基本断定是驱动程序问题.其次,点击扬声器,选择测试,查看扬声器是否好用,如 ...
- nano编辑器使用教程
使用Linux VPS会经常和编辑器打交道,一般常用的是vi和nano,虽然vi功能强大,但是相对新手来要稍微难上手,GNU nano是一个体积小巧而功能强大的文本编辑器.这里就简单说一下nano的使 ...
- bzoj3600: 没有人的算术
题意:太难说了..手动去看吧反正不是权限题. 膜拜VFK大爷的神题! 其实一开始思路挺清楚的,如果我们能做到用一个实数去代表"数",这就是裸的动态区间最值查询. 关键是怎么用实数去 ...
- UIApplication详解
每个app有且只有一个UIApplication对象,当程序启动的时候通过调用UIApplicationMain方法得到的.可以通过sharedApplication方法得到. UIApplicati ...