Manually realize the sequential execution of pop-up windows

To implement the sequential execution of pop-up windows, the next pop-up window pops up after the current pop-up window is closed, you can use the following method:

  1. Create a popup queue (array) to store the order of popups.
  2. When a popup needs to be displayed, add the popup to the end of the queue.
  3. Checks if the queue is empty, and if not, displays the first popup in the queue.
  4. When the current popup is closed, remove it from the queue and show the next popup (if the queue is not empty).
  5. Repeat step 4 until the queue is empty, that is, all pop-up windows have been displayed.

The following is a simple sample code that uses JavaScript to implement the above logic:

// 弹窗队列
var popupQueue = [];

// 添加弹窗到队列
function addPopupToQueue(popup) {
  popupQueue.push(popup);
  if (popupQueue.length === 1) {
    showNextPopup();
  }
}

// 显示下一个弹窗
function showNextPopup() {
  if (popupQueue.length > 0) {
    var nextPopup = popupQueue[0];
    nextPopup.show(); // 假设有一个show方法用于显示弹窗
  }
}

// 关闭当前弹窗
function closeCurrentPopup() {
  if (popupQueue.length > 0) {
    popupQueue.shift(); // 移除队列中的第一个弹窗

    if (popupQueue.length > 0) {
      showNextPopup(); // 显示下一个弹窗
    }
  }
}

// 示例用法
var popup1 = { // 第一个弹窗对象
  show: function() {
    console.log("显示弹窗1");
    // 显示弹窗1的代码...
  }
};

var popup2 = { // 第二个弹窗对象
  show: function() {
    console.log("显示弹窗2");
    // 显示弹窗2的代码...
  }
};

addPopupToQueue(popup1);
addPopupToQueue(popup2);

// 假设点击按钮后关闭当前弹窗
closeCurrentPopup();

In the above code, addPopupToQueuethe function is used to add the popup window to the queue, showNextPopupthe function is used to display the next popup window, and closeCurrentPopupthe function is used to close the current popup window. In the example, we create two popup objects and add them to the popup queue one by one. When the button is clicked, closeCurrentPopupthe function is called, the current popup will be closed and the next popup will be displayed.

Please note that the above is just a simple sample code, which may need to be adjusted and extended appropriately according to specific needs in actual situations.

Guess you like

Origin blog.csdn.net/weixin_54165147/article/details/131944095