version 1.1
This free project is our only one step towards making a better web by spending serious effort and time. Please support us by linking back to us and sharing on social media.
ToastX is a lightweight and flexible jQuery-based toast notification plugin designed to display elegant, animated toast messages with customizable options. It supports progress bars, animations, icons, and multiple positions for messages.
top-left
, bottom-center
).Include jQuery in your project (if not already included):
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
Include the ToastX plugin JavaScript file:
<script src="toastx.js"></script>
Optionally, include a CSS file for toast styling:
<link rel="stylesheet" href="toastx.css">
$.toastX("Hello, World!");
$.toastX("Custom message", {
position: "top-right",
duration: 5000,
animation: "slide",
showProgress: true,
progressBarColor: "#FF4500",
icon: "check",
type: "success",
onCreate: function (toast) {
console.log("Toast created:", toast);
},
onClose: function (toast) {
console.log("Toast closed:", toast);
}
});
$.toastX.removeAll();
$.toastX.removeAll('top-right');
Option | Type | Default | Description |
---|---|---|---|
position |
string |
bottom-center |
Position of the toast. Options: top-left , top-center , top-right , etc. |
duration |
number |
3000 |
Duration in milliseconds before the toast disappears. |
animation |
string |
none |
Animation type for entrance/exit. |
showProgress |
boolean |
true |
Whether to show a progress bar. |
progressBarColor |
string |
#99FF00 |
Color of the progress bar. |
progressBarClass |
string |
"" |
Additional CSS class for the progress bar. |
icon |
string |
null |
Icon class prefix (e.g., check , error ). Will be prefixed with toastx-icon- . |
type |
string |
"" |
Type of toast for styling purposes (e.g., success , error ). |
additionalClass |
string |
"" |
Additional CSS classes for custom styling. |
onCreate |
function |
null |
Callback function when the toast is created. |
onClose |
function |
null |
Callback function when the toast is closed. |
onBeforeCreate |
function |
null |
Callback function before the toast is created. |
onBeforeClose |
function |
null |
Callback function before the toast is closed. |
$.toastX("Success!", {
icon: "check",
type: "success",
position: "top-center"
});
$.toastX("Processing...", {
showProgress: true,
progressBarColor: "#FFD700",
duration: 4000
});
$.toastX.removeAll('bottom-center');
To style the toasts, you can use the following default classes or create your own:
.toastx-toast
: General toast styling..toastx-icon
: Icon styling..toastx-progress
: Progress bar wrapper..toastx-progress-bar
: Progress bar..toastx-[type]
: Specific types (e.g., success
, error
).
.toastx-yellow-bright {
background-image: linear-gradient(to bottom left, #FFFF99, #FFD700);
}
.toastx-yellow-warm {
background-image: linear-gradient(to bottom left, #FFDD44, #FFA500);
}
This plugin is open-sourced under the MIT License.