How to delay display of Bootstrap 3 modal after click
You can delay the click of the trigger button, then activate the modal directly:
$('[data-toggle=modal]').on('click', function (e) {
var $target = $($(this).data('target'));
$target.data('triggered',true);
setTimeout(function() {
if ($target.data('triggered')) {
$target.modal('show')
.data('triggered',false); // prevents multiple clicks from reopening
};
}, 3000); // milliseconds
return false;
});
http://jsfiddle.net/mblase75/H6UM4/
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/