Toastr JS让弹出提示信息一直可见

9
我正在尝试使用John Papa的Toastr插件显示一个toast消息。(http://codeseven.github.io/toastr/demo.html) 我无法找到一个选项,让toast在屏幕上一直保持显示状态,而不需要手动将"timeOut"和"extendedTimeOut"值设置为非常高的数字。是否有人知道如何实现这个功能?
toastr.options = {
    "closeButton": true,
    "timeOut": "500000",
    "extendedTimeOut": "100000"
}
toastr.error('Error!');
2个回答

19
根据代码,将它们设置为0。
timeOut: 5000, // Set timeOut and extendedTimeout to 0 to make it sticky

2
另外,我还需要将 "extendedTimeOut": 0 进行设置。 - Strabek
这对于Bootstrap 4适用,但是在Bootstrap 5中,选项无法正常工作。我将timeOut设置为0,将extendedTimeOut设置为0,但是toast仍然在短时间后关闭。 - Avner Moshkovitz
你确认它也适用于版本5 - https://stackoverflow.com/questions/75242712/toastr-options-not-working-with-bootstrap-5 - FrEaKmAn

1

要显示toast直到用户关闭,设置disableTimeOut和closeButton

        toastr.error("Message", "Title", { disableTimeOut: true, closeButton:true });

如果同时使用了Bootstrap 5,这个代码还能工作吗? - Avner Moshkovitz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接