点击按钮后,显示一个提示信息,然后自动消失
首先需要引入toastr.css和toastr.min.js
下载地址: 版本:latest 复制 标签 复制链接 https://cdn.bootcss.com/toastr.js/latest/css/toastr.css 复制 标签 复制链接 https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css 复制toastr.success(“祝贺你成功了”);
toastr.warning(“警告你别来烦我了”)
toastr.info(“这是一个提示信息”);
toastr.error(“出现错误,请更改”);
这个是清除信息弹框(有动画,动画执行完删除)
toastr.clear();
这个是删除信息弹框(没有动画,立即删除)
toastr.remove()
也可以调整弹框弹出位置和大小,如:
toastr.options = {
"closeButton": false, //是否显示关闭按钮
"debug": false, //是否使用debug模式
"positionClass": "toast-center-center",//弹出窗的位置
"showDuration": "300",//显示的动画时间
"hideDuration": "1000",//消失的动画时间
"timeOut": "5000", //展现时间
"extendedTimeOut": "1000",//加长展示时间
"showEasing": "swing",//显示时的动画缓冲方式
"hideEasing": "linear",//消失时的动画缓冲方式
"showMethod": "fadeIn",//显示时的动画方式
"hideMethod": "fadeOut" //消失时的动画方式
};
positionClass官方给的可选属性是,发现并没有水平垂直居中的
toast-top-left 顶端左边
toast-top-right 顶端右边
toast-top-center 顶端中间
toast-top-full-width 顶端,宽度铺满整个屏幕
toast-botton-right
toast-bottom-left
toast-bottom-center
toast-bottom-full-width
现在要在它的原css文件中自定义一个css样式
.toast-center-center {
top: 30%;
left: 50%;
margin-top: -30px;
margin-left: -150px;