不同類型的消息在網站依次彈出,某條消息中有操作時,操作完成后,繼續彈后面的消息,怎么做?
網站消息彈出順序安排
LEATH
2019-03-15 17:34:05
TA貢獻1815條經驗 獲得超10個贊
這種流程控制都應該用promise
// 簡易模態框const msg = text => { return new Promise(resolve=>{ const div = document.createElement("div"); div.setAttribute("style","position:fixed;left:50%;top:50%;width:200px;height:100px;transform:translate(-50%,-50%);z-index:9999;background:blue;"); div.innerText = text; const btn = document.createElement("button"); btn.setAttribute("style","position:absolute;right:0;top:-2em;"); btn.innerText = "關閉"; div.appendChild(btn); btn.addEventListener("click",()=>{ document.body.removeChild(div); resolve(); }); document.body.appendChild(div); }) }// 使用(async ()=>{ await msg("How are you"); await msg("Fine"); await msg("Thanks"); await msg("And you"); })()
舉報