Reputation: 89
After opening modal window, visible 2 scrolls (html and modal). I want to hide html overflow , and do visible after closing modal window. How do this without js? only by css
$('.modal').on('show', function() {
$("html").css({
overflow: 'hidden'
});
});
$('.modal').on('hide', function() {
$("html").css({
overflow: 'scroll'
});
});
Upvotes: 2
Views: 1008
Reputation: 1355
The correct event triggers for the Bootstrap's modal are 'show.bs.modal'
and 'hide.bs.modal'
Try this instead:
jQuery('.modal').on('show.bs.modal', function() {
jQuery("html").css({
overflow: 'hidden'
});
});
jQuery('.modal').on('hide.bs.modal', function() {
jQuery("html").css({
overflow: 'scroll'
});
});
But I strongly advise you to use the Bootstrap's method to show/hide a modal. It handles the HTML overflow automatically.
jQuery("#element").modal('show');
jQuery("#element").modal('hide');
Upvotes: 1