** Use mode **

Toast({ text: 'Hello,Baby! ', type: 'success', });Copy the code

** js **

/** * @param text Text required * @param duration Display duration Optional * @param type Icon failure message */ export default ({text, duration, type, }: { text: string; duration? : number; type: 'success' | 'error' | 'warn'; }) => { const node = document.getElementById('jd-toast'); if (node) document.body.removeChild(node); const m = document.createElement('div'); const toastId = Date.now() + ''; m.setAttribute('toastId', toastId); m.className = 'Toast'; m.id = 'jd-toast'; m.innerHTML = `<div><i class='toast-icon-${type}'></i><p>${text}</p><div>`; document.body.appendChild(m); SetTimeout (function() {const d = 0.5; m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in'; m.style.opacity = '0'; setTimeout(function() { const node1 = document.getElementById('jd-toast'); if (node1? .getAttribute('toastId') == toastId) document.body.removeChild(node1); }, d * 1000); }, duration || 2000); };Copy the code

** css **

.Toast {
    background: #000;
    border-radius: 8px;
    color: #fff;
    font-size: 28px;
    left: 50%;
    max-width: 62.6%;
    opacity: 0.7;
    padding: 0 5px;
    padding: 0.75rem 1rem;
    position: fixed;
    text-align: center;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 9999999999;
    i {
        &.toast-icon-success {
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAABGdBTUEAALGPC/xhBQAABkpJREFUaAXVm02MFFUUhacRRmNEQsBEJAGdZBwWIhp1QJTEmJgxURM0GDYkQoizMWFndIcbiQFXbF3iTjeaicmwQCM/mugQ/A1DwImiqCwwAgqKOn6Hft3z6nZVddXrVz3dNzlT7+fec8/t7ldV/bqmNlCRzc7O3gT1I+BBsAaMgBVgsQOHgUsOP3OcBifB5+BorVa7yrG3jSKXgZfAIXAVhJpixSGuZT1XNaJGwbvgLxDbxCnu0XkvHBHrwSTolinX+k4Kr4UEk3QpcW+AF0Eex3fMHwIngNao+r8DrV2Z1vMSMAS0xu8Dj7s+h1SbZfQt8Crr/LdUj5iDFLsJ/Aqy7FsmXgF3hu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Mosk3DnybavIyutufoX2kOdmnDdVgatrdLIWJITOprp636EuT9pR6hhLF4HDYOE0mHPqoQx32yaLDLfJxslubqv+JFsceH5BmCTfWuuWMQw18bRyPa7zHa2zKczVIs29f0UmvgYktvqdrx39KpikxbgO9dn9dJWzJzYLDQXl59gft+3ODemBSGoG0+nawrTS8h4F9MFTbnbe3DZ4nB2kD0uibaii2XYXjdj/StfV8R/BuSFWvhTQBabO2vVROovdZBvrawrmxFFGFztLiNHFI2L7SaQnXM1oTCZp6R6/mitKEkQOkAaS9s9Ksb4HljUDd+NtLFUOzP4GHyjPGiVBup4FDwqS1s29hEKwG3wBr2u3UDXrYqxlQu3K5nHanleHrGlcH0LaGQKZ32j7/oSSyL8FTrVFxR5TD5eLQYtLW2Ttr5UKoV/f1llRzAx/TtFs4lqZ0X5xA3FkmTdV9yiDfCuwF3hfzGZ1dIPjERuwdjkNcWSYNW8u+gun3mG1YSHQXLnro6+k2rvq3nI/AF0CbhTPgIvD/BeBW+uK7G+iZqsfAGpBnE0zuYu9MfN0zCte6srslDFVmylX5+aLtK4gIPaave3B/b4xuFBOnuMfaCum2A6JWgpeBNtztb1YMFTbFikNcK2PWEbSGiwhA6C34PQoeAFqf2hTXFxCNNy4hWsuXwS9gGmida7PtCOtT49Htf1NtEx4Pz1LmAAAAAElFTkSuQmCC');
        }
        &.toast-icon-error {
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADwAAAA8CAYAAAA6/NlyAAAABGdBTUEAALGPC/xhBQAABkhJREFUaAXVm1uIVXUUxufYSBGZhAaZoDVQ40OmUY1mCRFESQUWRg9JKZgvkW9Rj70koT3ZY48mEvWSDIE+2JAVQSl2xQltKLtaGKk1Rtr0++b8z5m119mXs2/jOQu+2f/LWt/61t5nn73Pf+9pDNRkU1NTV0B9N7gDLAPDYBGYF8Bm4GzAz2zHwTHwKfiw0WicZ9vbRpELwLPgIDgPippixSGuBT1XNaJGwNvgH1C1iVPcI5e8cESsAvvBbJlyrS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wjoQ1PcstbRD2wo8H/9RxvQrWN5l9OKU1oNIL7nCU+Xn4YNk9rhqAXaNTjc0rEI3DwFrfLd75HUQxfjHvsHx0Dsv2NTftv0+1W/3b8DXM1MjeGLKHN7T1vkVfGvpXxtQzFCkGh0POaX/EoY861OHfLDrUIR8nv7Sp+u/vcOzxAWmWcGedS844NMCXzvGIxnu8xra8UIM0W/uCTnwNTGywnqFd/VsybYnVNtDr19dVwobULDgckJexv2jflhrUA5PSCKTV2oFMaXhrWcS/GKq7pusygy+Rg7QBe2dHd7qG7parcN6kCGd6v6OW1ZAy+0magLR525SLl+idnoH+W+DyXEQ1OktL0MQmYjtzpyVc72iNRmiaHe3NRbkJKw6QBhB3ZKW5dQeZLyuBeozqL1UMTf0I7szHVp23cgcNbCImrTOPRYukhGAp+Ap4m2RAN+jF9mYBMcoVciq3N2n0KxwFshACkY60f/+jlfBzGg8VY+4+SjmAcsWZtJU7sl4KhNq7L8dlC2Pvs73Lx5XtixOIO8mkqb5PGeRah/IXeCvmEzrbQOEvNmKvDxziSjJp6HgambWD4+8xM6JIdCMueunr4QxX/VvOGPgMfAMmwBlg/wXgavriuxnonap7wTKQZqNMbmNNTHyzZxSu88qvljBUmylX7d8XmXsQEXpNX/fgdm2MbiUmTnFX/u8FmYVlOSBqMXgefAT+BUVNseIQ1+KsvHnmC53D3SRA6FX43QNuBzo/9aaBfoBovHUJ0bl8DvwCxoHOcy22fcD5qfHK7X8scfbOYfHKuAAAAABJRU5ErkJggg==');
        }
        &.toast-icon-warn {
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAgxJREFUSA29Vr1OAkEQ5vbuSh7Aix2NHQncU0iiUGhlQ60xsdDYGTsihYmxp7HSAjWeTwEkdDZ2hhewITm48/s2sxeMxx0EcJLNTubnm53ZudmzChk0HA63J5PJPkxqcRyXLMvyaA5+BP4TbOA4zku5XP6iPI2sNOFgMPCiKLqGrollp9nMyKbgO0qpq0qlMpqRa/ZPAIDvAfwB2iJWiPXMhZP2XNfVAGEYesjMh7wuy8X+jSBHCPIKPqFfAXq93ilSv0UJFPYu9nPf91mKuQQflq4N2wb2CPsZfO6MQxKAJ4eSp42xLqvVatsYLbL3+/1z2LVoi0ANk4kOIDX/gK4I5cWy4AQlMQgOeQOW5drhnSgq5EIJ3s0CRzkCrDf6pBF9iQFdUTALiq0IQRMrRHSmuRIJBpujSWwLaR1DeA/BEy7ncCV0cUaWj2APkM0JS1QTOS94XWSwagqnLxGVfZ6HLncQ5NkZLGI7SMMDUzAfUY7zbo5eq4mFD5Ht6ukuWsRpGRvbtpPviyVKPv9lQLJsx+PxFvXE5kjQo0BmS5bfwjqDRWyWyFwaB9e6yGAFivMcqBy5dXSJ7qhVoggGA0yJreSx6EDgIqW8AfcOO5Nx6jkEg+O7Q+z/GXZ66uGxQPQIkVsyelNPOE9oxjUx5OHR3Zn0Kx1Rv809OOZkG30yZ4Js7tE3Qbiv47flB40+NnUhqGKXAAAAAElFTkSuQmCC');
        }
        background-size: 100% 100%;
        display: block;
        height: 60px;
        margin: 0px auto;
        width: 60px;
    }
}
Copy the code