mrr*_*ot5 1 notifications toast twitter-bootstrap snackbar bootstrap-4
我正在尝试使用Bootstrap 4创建一个快餐/吐司版。我从w3schools的本教程开始。
更新:我正在尝试为Bootstrap 4实现自定义小吃栏或吐司,但是现在,由于@Zim所说,Bootstrap 4包含了4.2版中的此选项,因此没有必要。
Scr*_*t47 13
我(强调=完全公开)为Toasts组件创建了一个jQuery插件,以使其更易于使用,可在此处找到回购。目的是能够通过JavaScript即时调用祝酒词。
吐司
$.toast({
title: 'Toast',
subtitle: '11 mins ago',
content: 'Hello, world! This is a toast message.',
type: 'info',
delay: 5000
});
Run Code Online (Sandbox Code Playgroud)
小吃
$.toast({
title: 'A small bitesize snack, not a toast!',
type: 'info',
delay: 5000
});
Run Code Online (Sandbox Code Playgroud)
现场例子
$.toast({
title: 'Toast',
subtitle: '11 mins ago',
content: 'Hello, world! This is a toast message.',
type: 'info',
delay: 5000
});
Run Code Online (Sandbox Code Playgroud)
$.toast({
title: 'A small bitesize snack, not a toast!',
type: 'info',
delay: 5000
});
Run Code Online (Sandbox Code Playgroud)
(function(b){b.toast=function(a,h,g,l,k){b("#toast-container").length||(b("body").prepend('<div id="toast-container" aria-live="polite" aria-atomic="true"></div>'),b("#toast-container").append('<div id="toast-wrapper"></div>'));var c="",d="",e="text-muted",f="",m="object"===typeof a?a.title||"":a||"Notice!";h="object"===typeof a?a.subtitle||"":h||"";g="object"===typeof a?a.content||"":g||"";k="object"===typeof a?a.delay||3E3:k||3E3;switch("object"===typeof a?a.type||"":l||"info"){case "info":c="bg-info";
f=e=d="text-white";break;case "success":c="bg-success";f=e=d="text-white";break;case "warning":case "warn":c="bg-warning";f=e=d="text-white";break;case "error":case "danger":c="bg-danger",f=e=d="text-white"}a='<div class="toast" role="alert" aria-live="assertive" aria-atomic="true" data-delay="'+k+'">'+('<div class="toast-header '+c+" "+d+'">')+('<strong class="mr-auto">'+m+"</strong>");a+='<small class="'+e+'">'+h+"</small>";a+='<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">';
a+='<span aria-hidden="true" class="'+f+'">×</span>';a+="</button>";a+="</div>";""!==g&&(a+='<div class="toast-body">',a+=g,a+="</div>");a+="</div>";b("#toast-wrapper").append(a);b("#toast-wrapper .toast:last").toast("show")}})(jQuery);
const TYPES = ['info', 'warning', 'success', 'error'],
TITLES = {
'info': 'Notice!',
'success': 'Awesome!',
'warning': 'Watch Out!',
'error': 'Doh!'
},
CONTENT = {
'info': 'Hello, world! This is a toast message.',
'success': 'The action has been completed.',
'warning': 'It\'s all about to go wrong',
'error': 'It all went wrong.'
};
function show_random_toast()
{
let type = TYPES[Math.floor(Math.random() * TYPES.length)],
title = TITLES[type],
content = CONTENT[type];
$.toast({
title: title,
subtitle: '11 mins ago',
content: content,
type: type,
delay: 5000
});
}
function show_random_snack()
{
let type = TYPES[Math.floor(Math.random() * TYPES.length)],
content = CONTENT[type].replace('toast', 'snack');
$.toast({
title: content,
type: type,
delay: 5000
});
}Run Code Online (Sandbox Code Playgroud)
Bootstrap 4.2 现在包含Toast通知
下面是一个例子:
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="mr-auto">Title</strong>
<small>5 mins ago</small>
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="toast-body">
Content... this is a toast message.
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
更多 Bootstrap Toast 布局/位置示例:
垂直堆叠:https
:
//codeply.com/go/3ZvZa9b8Im并排:https : //codeply.com/go/GFMde2ritI
3x3 网格:https : //codeply.com/go/lj8GTFjvuK
| 归档时间: |
|
| 查看次数: |
23356 次 |
| 最近记录: |