banner.ejs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <div class="banner">
  2. <ul></ul>
  3. </div>
  4. <script>
  5. let banner = {
  6. errorList: [],
  7. notificationList: [],
  8. createNotification: function(value){
  9. this.notificationList.push(value);
  10. this.updateNotifications();
  11. setTimeout(()=>{
  12. this.notificationList.splice(0, 1);
  13. this.updateNotifications();
  14. }, 10000);
  15. },
  16. createError: function(value){
  17. this.errorList.push(value);
  18. this.updateNotifications();
  19. setTimeout(()=>{
  20. this.errorList.splice(0, 1);
  21. this.updateNotifications();
  22. }, 10000);
  23. },
  24. updateNotifications: function(){
  25. let ul = document.querySelector(".banner ul");
  26. while(ul.hasChildNodes()){
  27. ul.removeChild(ul.firstChild);
  28. }
  29. for(let notification of this.notificationList){
  30. let li = document.createElement("li");
  31. li.classList = "notification";
  32. li.innerText = notification;
  33. ul.appendChild(li);
  34. }
  35. for(let error of this.errorList){
  36. let li = document.createElement("li");
  37. li.classList = "error";
  38. li.innerText = error;
  39. ul.appendChild(li);
  40. }
  41. }
  42. }
  43. </script>