banner.ejs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 banner = document.querySelector(".banner");
  26. let ul = document.querySelector(".banner ul");
  27. while(ul.hasChildNodes()){
  28. ul.removeChild(ul.firstChild);
  29. }
  30. for(let i = 0; i < this.notificationList.length; i++){
  31. let li = document.createElement("li");
  32. li.classList = "notification";
  33. li.innerText = this.notificationList[i];
  34. ul.appendChild(li);
  35. }
  36. for(let i = 0; i < this.errorList.length; i++){
  37. let li = document.createElement("li");
  38. li.classList = "error";
  39. li.innerText = this.errorList[i];
  40. ul.appendChild(li);
  41. }
  42. }
  43. }
  44. </script>