Reputation: 41
I'm using bootstrap modal, I added a scroll bar and it works fine with the mouse, but when I use the keyboard only the background page scrolls. What can I do to solve this. This is the css code that I'm using.
.modal .modal-body {
height: 520px;
overflow-y: auto;
}
I tried this code but it doesn't work
$('#myModal').keydown(function(e)
{
if(e.keyCode == 40){$('.modal-body').scrollTop($('.modal-body').scrollTop()+10);}
if(e.keyCode == 38){$('.modal-body').scrollTop($('.modal-body').scrollTop()-10);}
});
Upvotes: 1
Views: 3044
Reputation: 5188
Keystrokes are only detected by the element that currently has the focus, so your keydown
event won't trap anything if the focus is on an element in the background. I suggest doing the following:
tabIndex=-1
attributeUpvotes: 7