Yes it is possible, there are different ways, one of them is using JavaScript / jQuery to know the dimensions and position of the element to be able to synchronize the scroll with those values.
If you use .offset()
you can know where the element begins and adding it to .outerHeight()
knows where it ends. Then you need to know the value of scroll and you can get it with .scroll()
. To end, and since the scroll event is not cancelable, you must re-type the scroll value if it passes "the boundaries."
Code hint:
var ultimoScroll;
var dialogPosition = $('#seu_dialog').offset().top;
var dialogHeight = $('#seu_dialog').outerHeight();
$(window).on('scroll', function () {
var scroll = $(this).scrollTop();
if (scroll > dialogPosition + dialogHeight.outerHeight() || scroll < dialogPosition) $(window).scrollTop(ultimoScroll);
else ultimoScroll = scroll;
});
This is the skeleton of what you need. Since I did not give any HTML / CSS / JS code I leave an example invented by me that with an adaptation of this code I mentioned above: link