返回 jQuery 实例与特效代码列表
弹窗与提示MIT兼容 jQuery 1.12 / 3.8 / 4.1

消息提示条(Toast)

非阻塞式轻量通知条,支持成功、警告、错误三种语义样式并可多条堆叠自动消失。

兼容性说明:全版本兼容;使用 CSS 过渡动画,slim 精简版同样可用。

在线交互演示(独立沙箱)

$(function () {
  function showToast(type, text) {
    var $el = $('<div class="ts-item"></div>').addClass(type).text(text);
    $('#ts-stack').append($el);
    setTimeout(function () { $el.remove(); }, 2400);
  }
  $('.ts-btns').on('click', '.ts-btn', function () {
    showToast($(this).data('type'), $(this).data('msg'));
  });
});
不用 jQuery 怎么写?(现代原生 JS / CSS 替代思路)

动态 document.createElement('div') 插入固定定位容器,配合 setTimeout 移除即可。

const el = document.createElement('div');
el.className = 'toast ok'; el.textContent = msg;
stack.append(el); setTimeout(() => el.remove(), 2400);