Tuesday, October 14, 2025
HomejQuerySwipe-to-Dismiss Toast Notification Plugin - jQuery swipetoast

Swipe-to-Dismiss Toast Notification Plugin – jQuery swipetoast


swipetoast is a light-weight but highly effective jQuery toast notification plugin that implements swipe gestures for dismissal whereas sustaining compatibility with conventional click on interactions.

The swipe dealing with is managed by the initSwipeHandler methodology. This makes use of normal touchstart, touchmove, touchend (and their mouse occasion equivalents) to trace the person’s swipe gesture. It calculates the gap swiped and adjusts the toast’s remodel and opacity accordingly. As soon as the swipe distance exceeds a threshold (configurable through the swipeThreshold possibility), the toast is dismissed. I respect that it makes use of CSS transitions for easy animations, leveraging the browser’s built-in capabilities.

Options:

  • Swipe-to-dismiss performance for higher cell interplay
  • Totally responsive design that works throughout all gadget sizes
  • 9 totally different positioning choices (top-left, top-center, top-right, center-left, heart, center-right, bottom-left, bottom-center, bottom-right)
  • Customizable length settings, together with everlasting toasts
  • A number of toast varieties (default, success, error, warning, information)
  • Non-obligatory progress bar to visually point out remaining time
  • RTL help for worldwide functions
  • Customized styling choices by way of further CSS lessons
  • Non-obligatory shut button for conventional dismissal
  • Set off customized capabilities when your toast triggered and dismissed

How you can use it:

1. Be sure to have the newest jQuery library loaded in your doc. Then, embrace SwipeToast’s CSS and JavaScript information:


<!-- jQuery is required -->
<script src="/path/to/cdn/jquery.min.js"></script>

<!-- jQuery swipetoast Plugin -->
<hyperlink rel="stylesheet" href="jquery.swipetoast.min.css">
<script src="jquery.swipetoast.min.js"></script>

2. Create a fundamental toast notification that seems on the bottom-center of the display screen and disappears after 4 seconds:


$.swipeToast({
  message: 'jQueryScript.Internet!',
});

3. Customise the toast’s habits and look with the next choices:

  • message (string): The textual content to show.
  • kind (string): ‘default’, ‘success’, ‘error’, ‘warning’, or ‘information’.  
  • length (quantity): How lengthy the toast is seen in milliseconds. Set to `0 to make it persistent (till dismissed).
  • swipeable (boolean):  true to allow swipe-to-dismiss, false to disable.
  • place (string): The place the toast seems.  Choices are: ‘top-left’, ‘top-center’, ‘top-right’, ‘center-left’, ‘heart’, ‘center-right’, ‘bottom-left’, ‘bottom-center’, ‘bottom-right’.
  • rtl (boolean): true for right-to-left languages, false for left-to-right.
  • closeButton (boolean): Exhibits a detailed button if `true`.
  • progressBar (boolean):  Shows a progress bar if `true`.
  • onOpen (perform): A callback perform that executes when the toast seems.
  • onClose (perform): A callback that runs when the toast is dismissed.
  • className (string): You too can add different CSS lessons.
  • offset (quantity): You may change the gap from the sides.
  • swipeThreshold (quantity): From a scale of 0 to 1, you may change the edge.

$.swipeToast({
  message: '',
  kind: 'default',
  length: 4000,
  swipeable: true,
  place: 'bottom-center',
  rtl: false,
  closeButton: false,
  progressBar: false,
  onOpen: null,
  onClose: null,
  className: '',
  offset: 24,
  swipeThreshold: 0.5
});

FAQs:

Q: What occurs if I name $.swipeToast() a number of occasions shortly?

A: Every name creates a brand new toast. They’re going to stack up within the specified container. When you’re quickly creating and dismissing toasts, ensure your length is brief sufficient, or use the onClose callback to handle them programmatically.

Q: Can I customise the looks past the built-in varieties?

A: Completely. Use the className possibility so as to add your individual CSS lessons, after which fashion these lessons in your stylesheet. This offers you full management over the appear and feel. You can even override the default types for the built-in varieties (.swipetoast.success, .swipetoast.error, and so on.) for those who needed to.

Q: Does SwipeToast help HTML content material in notifications?

A: The present implementation treats the message as textual content content material. When you want HTML content material, you would wish to change the library to make use of .html() as an alternative of .textual content() when setting the message. Nevertheless, be cautious with this method because it might introduce XSS vulnerabilities for those who’re displaying user-generated content material.

Q: How does SwipeToast deal with a number of notifications without delay?

A: SwipeToast manages a number of notifications by stacking them throughout the container for his or her designated place. Notifications function independently, so dismissing one does not have an effect on others. The library intelligently creates position-specific containers solely when wanted, which helps preserve efficiency even with a number of toasts.


This superior jQuery plugin is developed by salarizadi. For extra Superior Usages, please examine the demo web page or go to the official web site.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments