How to delay display of Bootstrap 3 modal after click

前端 未结 4 1243
情歌与酒
情歌与酒 2020-12-18 04:16

I\'m trying to delay the display of a Bootstrap modal after the user has clicked on a trigger button:

4条回答
  •  無奈伤痛
    2020-12-18 04:57

    Use .on() to hook into the event:

    var isFirstShowCall = false;
    
    $('#myModal').on('show.bs.modal', function (e) {
        isFirstShowCall = !isFirstShowCall; // Prevents an endless recursive call
        if(isFirstShowCall) {
                e.preventDefault(); // Prevent immediate opening
                window.setTimeout(function(){
                    $('#myModal').modal('show');
                }, 3000)
        }
    });
    

    http://jsfiddle.net/G9XeA/

提交回复
热议问题