弹出层小插件之(一)sweetalert

//弹出层小插件之(一)sweetalert

1.引入sweetalert.css

2.引入sweetalert.min.js

下载地址:http://t4t5.github.io/sweetalert/

官网有如下多种你需要的展示效果

More examples

In these examples, we‘re using the shorthand function swal to call sweetAlert.

  • A basic message
  • swal("Here‘s a message!")
  • <link rel="stylesheet" type="text/css" href="dist/sweetalert.css">
    			<link rel="stylesheet" type="text/css" href="themes/twitter.css">

Download & install

Method 1: Install through bower:

$ bower install sweetalert

Method 2: Install through NPM:

$ npm install sweetalert

Method 3: Download the sweetAlert CSS and JavaScript files.

Download files

  1. Initialize the plugin by referencing the necessary files:

    <script src="dist/sweetalert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="dist/sweetalert.css">
  2. Call the sweetAlert-function after the page has loaded
    swal({
      title: "Error!",
      text: "Here‘s my error message!",
      type: "error",
      confirmButtonText: "Cool"
    });
    
  • 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: "You 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: "You 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
  • swal({
      title: "Sweet!",
      text: "Here‘s a custom image.",
      imageUrl: "images/thumbs-up.jpg"
    });
  • An HTML message
  • swal({
      title: "HTML <small>Title</small>!",
      text: "A custom <span style="color:#F8BB86">html<span> message.",
      html: true
    });
  • A message with auto close timer
  • swal({
      title: "Auto close alert!",
      text: "I will close in 2 seconds.",
      timer: 2000,
      showConfirmButton: false
    });
  • A replacement for the "prompt" function
  • swal({
      title: "An input!",
      text: "Write something interesting:",
      type: "input",
      showCancelButton: true,
      closeOnConfirm: false,
      animation: "slide-from-top",
      inputPlaceholder: "Write something"
    },
    function(inputValue){
      if (inputValue === false) return false;
      
      if (inputValue === "") {
        swal.showInputError("You need to write something!");
        return false
      }
      
      swal("Nice!", "You wrote: " + inputValue, "success");
    });
  • With a loader (for AJAX request for example)
  • swal({
      title: "Ajax request example",
      text: "Submit to run ajax request",
      type: "info",
      showCancelButton: true,
      closeOnConfirm: false,
      showLoaderOnConfirm: true,
    },
    function(){
      setTimeout(function(){
        swal("Ajax request finished!");
      }, 2000);
    });
  • You can also change the theme of SweetAlert!
时间: 2024-08-05 15:29:49

弹出层小插件之(一)sweetalert的相关文章

【jquery】fancybox 是一款优秀的 jquery 弹出层展示插件

今天给大家分享一款优秀的 jquery 弹出层展示插件 fancybox.它除了能够展示图片之外,还可以展示 flash.iframe 内容.html 文本以及 ajax 调用,我们可以通过 css 来自定义外观. fancybox 特点: 可以支持图片.html 文本.flash 动画.iframe 以及 ajax 的支持: 可以自定义播放器的 css 样式: 可以以组的形式进行播放: 如果将鼠标滚动插件(mouse wheel plugin)包含进来的话 fancybox 还能支持鼠标滚轮滚

jQuery Dialog弹出层对话框插件

Dialog.js的相关注释已经添加,可以按照注释,进行相关样式的修改,适用于自定义的各个系统! dialog.js 1 /** 2 * jQuery的Dialog插件. 3 * 4 * @param object content 5 * @param object options 选项. 6 * @return 7 */ 8 function Dialog(content, options) 9 { 10 var defaults = { // 默认值. 11 title:'标题', // 标

jQuery弹出层layer插件的使用

引入插件layer 触发弹出层的按钮/链接 <a href="javascript:showPop();"> <img src="" /> </a> 弹出层内容 <div style="display: none"> <div id="attention" style="text-align:left;max-height:5rem;overflow-y:scro

改善用户体验之wordpress添加图片弹出层效果 (插件 FancyBox)

下面说说在改善用户体验之wordpress添加图片弹出层效果.效果图如下: 像这篇文章如何在百度搜索结果中显示网站站点logo? 文章内有添加图片,没加插件之前用户点击图片时,是直接_black打开新窗口到 图片地址,非常不友好,很不和谐!添加wordpress添加图片弹出层效果之后如上所示效果.逼格瞬间提高! 打造这个效果的这款插件名称是FancyBox for WordPress

【转】10 个很有用的 jQuery 弹出层提示插件

模态对话框为网站用户提供了快速显示信息的方法,也可以用来提示错误.警告和确认等信息,这里介绍了 10 个弹出模态对话框插件. How to Create a jQuery Confirm Dialog Replacement Open Source TinyBox2 JavaScript Modal Windows Apprise: Attractive Alert and Dialog Box for jQuery noty Reveal: jQuery Modals Made Easy A

magnific-popup 一款优秀, 多种功能于一身的弹出层jQuery插件.

功能很强大:灯箱, 画廊, 放大图片, 弹出Youtube GoogleMap, ajax读取popup等等文档:http://dimsemenov.com/plugins/magnific-popup/documentation.htmlExamples:http://dimsemenov.com/plugins/magnific-popup/

jQuery 插件开发——PopupLayer(弹出层)

导读:上次写了一篇关于GridView的插件开发方法,上几天由于工作需要,花了一天左右的事件封装了popupLayer(弹出层)插件.今天有时间就记录一下自己的开发思想与大家分享下,同时也算是对这段时间的工作概要吧. 就我在开发过程中的理解和开发的经验,一般常用的弹出层有三类(其实还有一类就是弹出可以输入内容的,但是这种可以被替代,所以就特别拿出来写了):Confirm.Alert.LoadContent(url).其中Alert又可以分成五种(当然也可以是四种),分别是: "error&quo

一款基于jQuery外观优雅带遮罩弹出层对话框

今天我们要来分享一款基于jQuery的弹出层对话框插件,该插件包含多种对话框类型,比如提示框.确认框等.更为实用的是,这款jQuery对话框中的按钮事件也可以被我们所捕获,从而相应对话框按钮的各种事件,用起来非常方便. 在线预览   源码下载 实现的代码. html代码: <center class="demo"> <button onclick="payment();">缴费提示层</button> <button onc

jquery 弹出层插件fancybox和放大镜插件cloud-zoom

这两天做了一个网上的项目,其实也不是自己做的,嘿嘿,现在就来说说我对这个小页面效果代码的理解代码下载 1.添加javascript引用和CSS文件的引用 //js代码的引用<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> <script src="fancybox/jquery.easing-1.3