首页 > 其他分享 >jquery.toast提示框案例

jquery.toast提示框案例

时间:2022-11-11 00:33:28浏览次数:36  
标签:jquery toast function text showMsg 提示框 click

<!doctype html>
        <html lang="zh">
        <head>
            <meta charset="utf-8">
            <title>JQuery信息提示框插件 jquery.toast.js 的使用</title>
            <link href="https://cdn.bootcss.com/jquery-toast-plugin/1.3.2/jquery.toast.css" rel="stylesheet">
            <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
            <script src="https://cdn.bootcss.com/jquery-toast-plugin/1.3.2/jquery.toast.min.js"></script>
        </head>

<body>
<button class="btn btn-success" name="success"id="simple"> 简单文本的消息提示框 </button>
<button class="btn btn-success" name="success"id="success"> 成功 </button>
<button class="btn btn-info" name="info"id="info">提示</button>
<button class="btn btn-warning" name="warning"id="warning">警告</button>
<button class="btn btn-danger" name="error"id="error">错误</button>

<script>
    $(function(){
        $("#simple").click(function(){
            $.toast('Here you can put the text of the toast');
        })

        $("#success").click(function(){
            showMsg("成功样式!", "success", 2000);
        })
        $("#info").click(function(){
            showMsg("提示样式!", "info", 2000);
        });

        $("#warning").click(function(){
            showMsg("警告样式!", "warning", 2000);
        })
        $("#error").click(function(){
            showMsg("错误样式!", "error", 2000);
        })

    });

    /**
     * 提示框
     * @param text
     * @param icon
     * @param hideAfter
     */
    function showMsg(text, icon, hideAfter) {
        if (heading == undefined) {
            var heading = "提示";
        }
        $.toast({
            text: text,//消息提示框的内容。
            heading: heading,//消息提示框的标题。
            icon: icon,//消息提示框的图标样式。
            showHideTransition: 'fade',//消息提示框的动画效果。可取值:plain,fade,slide。
            allowToastClose: false,//是否显示关闭按钮。(true 显示,false 不显示)
            hideAfter: hideAfter,//设置为false则消息提示框不自动关闭.设置为一个数值则在指定的毫秒之后自动关闭消息提框
            stack: 1,//消息栈。同时允许的提示框数量
            position: 'top-center',//消息提示框的位置:bottom-left, bottom-right,bottom-center,top-left,top-right,top-center,mid-center。
            textAlign: 'left',//文本对齐:left, right, center。
            loader: false,//是否显示加载条
            //bgColor: '#FF1356',//背景颜色。
            //textColor: '#eee',//文字颜色。
            loaderBg: '#ffffff',//加载条的背景颜色。

            beforeShow: function(){
                // alert('The toast is about to appear');
            },

            afterShown: function () {
                // alert('Toast has appeared.');
            },

            beforeHide: function () {
                // alert('Toast is about to hide.');
            },

            afterHidden: function () {
                // alert('Toast has been hidden.');
            }

            /*toast事件
            beforeShow 会在toast即将出现之前触发
            afterShown 会在toast出现后触发
            beforeHide 会在toast藏起来之前触发
            afterHidden 会在toast藏起来后被触发
            */
        });
    }

</script>
</body>
</html></title>
</head>
<body>

</body>
</html>

  

<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>JQuery信息提示框插件 jquery.toast.js 的使用</title>
<link href="https://cdn.bootcss.com/jquery-toast-plugin/1.3.2/jquery.toast.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-toast-plugin/1.3.2/jquery.toast.min.js"></script>
</head>

<body>
<button class="btn btn-success" name="success"id="simple"> 简单文本的消息提示框 </button>
<button class="btn btn-success" name="success"id="success"> 成功 </button>
<button class="btn btn-info" name="info"id="info">提示</button>
<button class="btn btn-warning" name="warning"id="warning">警告</button>
<button class="btn btn-danger" name="error"id="error">错误</button>

<script>
$(function(){
$("#simple").click(function(){
$.toast('Here you can put the text of the toast');
})

$("#success").click(function(){
showMsg("成功样式!", "success", 2000);
})
$("#info").click(function(){
showMsg("提示样式!", "info", 2000);
});

$("#warning").click(function(){
showMsg("警告样式!", "warning", 2000);
})
$("#error").click(function(){
showMsg("错误样式!", "error", 2000);
})

});

/**
* 提示框
* @param text
* @param icon
* @param hideAfter
*/
function showMsg(text, icon, hideAfter) {
if (heading == undefined) {
var heading = "提示";
}
$.toast({
text: text,//消息提示框的内容。
heading: heading,//消息提示框的标题。
icon: icon,//消息提示框的图标样式。
showHideTransition: 'fade',//消息提示框的动画效果。可取值:plain,fade,slide。
allowToastClose: false,//是否显示关闭按钮。(true 显示,false 不显示)
hideAfter: hideAfter,//设置为false则消息提示框不自动关闭.设置为一个数值则在指定的毫秒之后自动关闭消息提框
stack: 1,//消息栈。同时允许的提示框数量
position: 'top-center',//消息提示框的位置:bottom-left, bottom-right,bottom-center,top-left,top-right,top-center,mid-center。
textAlign: 'left',//文本对齐:left, right, center。
loader: false,//是否显示加载条
//bgColor: '#FF1356',//背景颜色。
//textColor: '#eee',//文字颜色。
loaderBg: '#ffffff',//加载条的背景颜色。

beforeShow: function(){
// alert('The toast is about to appear');
},

afterShown: function () {
// alert('Toast has appeared.');
},

beforeHide: function () {
// alert('Toast is about to hide.');
},

afterHidden: function () {
// alert('Toast has been hidden.');
}

/*toast事件
beforeShow 会在toast即将出现之前触发
afterShown 会在toast出现后触发
beforeHide 会在toast藏起来之前触发
afterHidden 会在toast藏起来后被触发
*/
});
}

</script>
</body>
</html></title>
</head>
<body>

</body>
</html>

标签:jquery,toast,function,text,showMsg,提示框,click
From: https://www.cnblogs.com/2019gdiceboy/p/16879338.html

相关文章

  • jQuery-tmpl 模板引擎使用方法说明
    jQuery-tmpl的几种常用标签分别有:${}{{each}}{{if}}{{else}}{{html}}不常用标签是:{{=}}{{tmpl}}{{wrap}}1、${}和{{=}}${}等同于{{=}},输出变量,${}里面还可以放表达式(=和......
  • Web前端--Jquery获取域名的更目录
    jquery取得文件根目录functiongetRootPath(){//获得根目录varstrFullPath=window.document.location.href;varstrPath=window.document.location.pa......
  • jQuery实现无刷新切换主题皮肤功能
    参考一主题皮肤切换功能在很多网站和系统中应用,用户可以根据此功能设置自己喜欢的主题颜色风格,增强了用户体验。本文将围绕如何使用jQuery实现点击无刷新切换主题皮肤功能......
  • 利用snowfall.jquery.js实现满屏爱心表白代码
    利用snowfall.jquery.js实现满屏爱心表白代码一、效果展示二、代码分析第一步:利用伪元素before和:after画两个重叠在一起的长方形,如图所示:<!DOCTYPEhtml><html><head>......
  • day28 jQuery
    概述:jQuery是一个轻量级的js库,它将js的功能进行了封装(所有的内容都是函数),它在封装的基础上做了进一步的兼容(兼容性好)特点:(优势)可链式调用(里......
  • 12个方便易用的jquery表单验证插件
    绝大部分网站都是开放注册的,而注册就需要使用表单验证,因为网站都需要对注册用户的信息安全性和合理性做出判断,表单的注册都应该具备完善的验证方式,比如注册使用的手机号是否......
  • jquery实现简单富文本编辑
      <script>$("#under").click(function(){varsec=getSelection()if(sec==undefined){return;......
  • jq(JQuery)操作cookie
     先引入jq封装好的方法<scriptsrc="//cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> 设置新的cookie$.cookie('name','yvioo');//设......
  • jQuery实现下拉选项框
    html文件:<!DOCTYPEhtml><html><head><metacharset="utf-8"><title></title><style>*{padding:0px;margin:0px;}.content{width:10......
  • jquery(js)实现上滑加载更多内容(分页查询)
    移动端上滑加载更多步骤移动端实现滚动上滑加载更多内容分为以下几步:步骤1禁用系统滚动条使用CSS样式禁用移动端的滚动条,代码如下所示:html,body{width:100%;overflow:hidde......