Skip to content
文章目录

说明

根据bootstrap官方组件toastsprogress封装的一个消息通知插件

用法

javascript
$.toasts({
    //配色方案 primary secondary success danger warning info dark light
    type: 'danger',
    // autohide: false,
    title: '这是标题',
    image: '../dist/img/favicon-16x16.png',
    //鼠标移入进度条暂停
    hoverProgressPause: true,
    //toast是否添加关闭按钮
    btnClose: true,

    content: '系统错误~',
    placement: 'top-left',
    delay: 5000,
    subTitle: '11分钟前aaa',
    body: `这是简单的内容`,
    animation: true,
    autohide: true
})

选项

选项类型默认值说明
hoverProgressPauseBooleantrue鼠标移入进度条暂停
btnCloseBooleantruetoast是否添加关闭按钮
titleString''标题
contentString''内容部分,该配置会和title和body互斥
imageString''头部的img的src属性
imageHeightString''图片的高度
imageAltString''图片的alt属性
subTitleString''头部的副标题
bodyString''正文内容此选项完全可以自定义body的内容
zIndexInteger1081toast容器的堆叠顺序
animationBooleantrue将过渡应用到toast
autohideBooleantrue自动隐藏toast
delayInteger5000延迟隐藏toast(单位:毫秒)
placementString'top-right'方位值,支持的方位参考:https://getbootstrap.com/docs/5.3/components/toasts/#placement
typeString'primary'情景色
onShownull、functionnullshow调用实例方法时会立即触发此事件
onShownnull、functionnull当 toast 对用户可见时会触发此事件
onHidenull、functionnullhide调用实例方法时会立即触发此事件
onHiddennull、functionnull当 toast 完成对用户隐藏时将触发此事件

方法

方法说明
hide关闭消息通知

例子:

javascript
//它的返回的是一个taost实例
let instance = $.toasts({
    type: 'success',
    content: '登录成功',
    autohide:false,
    btnClose:false
})

// 当你配置 autohide:false,且 btnClose:false 页面上没有任何可以关闭toast的按钮时该方法很有用
// 关闭toast
instance.hide();

Released under the MIT License.