UNPKG

yzhannotify

Version:

Only 0.78kB 用原生 JavaScript 在视窗或元素指定位置发通知和提示。Element and Global Notifications / Toasts with Pure / Vanilla / Native JavaScript.

2 lines (1 loc) 1.53 kB
(function(a,o){typeof exports=="object"&&typeof module<"u"?module.exports=o():typeof define=="function"&&define.amd?define(o):(a=typeof globalThis<"u"?globalThis:a||self,a.YZhanNotify=o())})(this,function(){"use strict";function a(o){var V=o.msg,A=o.position||"top center",f=o.ele,B=Math.max(300,o.duration||2500),Y=o.className,c="yznotify",m="arrow",p="ele",d="global",x="content",g="fade",b="in",z="out",W="pos";function T(e){return Array.prototype.slice.call(e)}function t(){return c+"-"+T(arguments).join("-")}function h(){return T(arguments).join(" ")}function X(e){return document.getElementById(e)}function N(e){return document.createElement(e)}function I(e,y,C,H,L,M){return e==="bottom"&&(C+=L),e==="right"&&(y+=H),e==="center"&&(M==="top"||M==="bottom"?y+=H/2:C+=L/2),[y,C]}var i=A.split(" "),r=i[0],s=i[1],n=N("DIV"),v=N("DIV");if(n.className=h(c,t(g,b),Y),v.innerHTML=V,v.className=t(x),n.appendChild(v),f){n.className+=" "+h(t(p),t(p,0,r),t(p,1,s),t(m),t(m,r),t(m,W,s));var l=f.offsetLeft,u=f.offsetTop,E=f.offsetWidth,j=f.offsetHeight,i=I(r,l,u,E,j);l=i[0],u=i[1],i=I(s,l,u,E,j,r),l=i[0],u=i[1],n.style.left=l+"px",n.style.top=u+"px",document.body.appendChild(n)}else{var D=t(c,d,r,s);let e=X(D);e===null&&(e=N("DIV"),e.id=D,e.className=h(t(d),t(d,r),t(d,s)),document.body.appendChild(e)),e.appendChild(n)}return setTimeout(function(){n.className=n.className.replace(t(g,b),t(g,z)),setTimeout(function(){var e=n.parentNode;e.removeChild(n),e.innerHTML===""&&e.parentNode.removeChild(e)},200)},B-200),n}return a});