mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-07 04:54:24 +01:00
Add interactive positioning widget
This commit is contained in:
parent
5b0dcf8ffe
commit
6c069b6976
@ -28,6 +28,17 @@
|
|||||||
new bootstrap.Popover(popover)
|
new bootstrap.Popover(popover)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var toastPlacement = document.getElementById('toastPlacement')
|
||||||
|
if (toastPlacement) {
|
||||||
|
document.getElementById('selectToastPlacement').addEventListener('change', function () {
|
||||||
|
if (!toastPlacement.dataset.originalClass) {
|
||||||
|
toastPlacement.dataset.originalClass = toastPlacement.className
|
||||||
|
}
|
||||||
|
|
||||||
|
toastPlacement.className = toastPlacement.dataset.originalClass + ' ' + this.value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
document.querySelectorAll('.toast')
|
document.querySelectorAll('.toast')
|
||||||
.forEach(function (toastNode) {
|
.forEach(function (toastNode) {
|
||||||
var toast = new bootstrap.Toast(toastNode, {
|
var toast = new bootstrap.Toast(toastNode, {
|
||||||
|
@ -135,17 +135,35 @@ Building on the above example, you can create different toast color schemes with
|
|||||||
|
|
||||||
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.
|
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.
|
||||||
|
|
||||||
{{< example class="bg-dark bd-example-toasts p-0">}}
|
{{< example >}}
|
||||||
<div aria-live="polite" aria-atomic="true" class="position-relative">
|
<form>
|
||||||
<div class="toast position-absolute top-0 end-0 m-3">
|
<div class="form-group mb-3">
|
||||||
<div class="toast-header">
|
<label for="selectToastPlacement">Toast placement</label>
|
||||||
{{< placeholder width="20" height="20" background="#007aff" class="rounded me-2" text="false" title="false" >}}
|
<select class="form-select mt-2" id="selectToastPlacement">
|
||||||
<strong class="me-auto">Bootstrap</strong>
|
<option value="" selected>Select a position...</option>
|
||||||
<small>11 mins ago</small>
|
<option value="top-0 start-0">Top left</option>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
<option value="top-0 start-50 translate-middle-x">Top center</option>
|
||||||
</div>
|
<option value="top-0 end-0">Top right</option>
|
||||||
<div class="toast-body">
|
<option value="top-50 start-0 translate-middle-y">Middle left</option>
|
||||||
Hello, world! This is a toast message.
|
<option value="top-50 start-50 translate-middle">Middle center</option>
|
||||||
|
<option value="top-50 end-0 translate-middle-y">Middle right</option>
|
||||||
|
<option value="bottom-0 start-0">Bottom left</option>
|
||||||
|
<option value="bottom-0 start-50 translate-middle-x">Bottom center</option>
|
||||||
|
<option value="bottom-0 end-0">Bottom right</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
<div aria-live="polite" aria-atomic="true" class="bg-dark position-relative bd-example-toasts">
|
||||||
|
<div class="toast-container position-absolute p-3" id="toastPlacement">
|
||||||
|
<div class="toast">
|
||||||
|
<div class="toast-header">
|
||||||
|
{{< placeholder width="20" height="20" background="#007aff" class="rounded me-2" text="false" title="false" >}}
|
||||||
|
<strong class="me-auto">Bootstrap</strong>
|
||||||
|
<small>11 mins ago</small>
|
||||||
|
</div>
|
||||||
|
<div class="toast-body">
|
||||||
|
Hello, world! This is a toast message.
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -158,8 +176,8 @@ For systems that generate more notifications, consider using a wrapping element
|
|||||||
<!-- Position it: -->
|
<!-- Position it: -->
|
||||||
<!-- - `.toast-container` for spacing between toasts -->
|
<!-- - `.toast-container` for spacing between toasts -->
|
||||||
<!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner -->
|
<!-- - `.position-absolute`, `top-0` & `end-0` to position the toasts in the upper right corner -->
|
||||||
<!-- - `.m-3` to prevent the toasts from sticking to the edge of the container -->
|
<!-- - `.p-3` to prevent the toasts from sticking to the edge of the container -->
|
||||||
<div class="toast-container position-absolute top-0 end-0 m-3">
|
<div class="toast-container position-absolute top-0 end-0 p-3">
|
||||||
|
|
||||||
<!-- Then put toasts within -->
|
<!-- Then put toasts within -->
|
||||||
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
<div class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user