0

I'm using Custombox to open a modal. This modal however can get a little long so I added a "Go To Top" button.

I found this at SO and I've been trying different combinations to make the modal scroll back up.

I've tried:

$("html, body").animate({
    scrollTop: $("#modal-id").offset().top
}, 800);

and a handful of different combinations for getting the offset but I can't get it to scroll to the top of the modal.

Community
  • 1
  • 1
Patrick Gregorio
  • 4,014
  • 1
  • 28
  • 52

1 Answers1

1

The scrollbar belongs to the .custombox-modal-wrapper element, so you should scroll it, not <body> or <html>:

$(".custombox-modal-wrapper").animate({
    scrollTop: $("#modal-id").offset().top
}, 800);
Michał Perłakowski
  • 70,955
  • 24
  • 137
  • 155
  • Hey, this worked! When I tried using a different element I used the `.custombox-modal-container` `div` and it didn't work. How do I determine which element has the scrollbar? – Patrick Gregorio Apr 04 '16 at 18:59
  • @PatrickGregorio I just inspected the gray background in Chrome DevTools and found out it's this element. – Michał Perłakowski Apr 04 '16 at 19:02
  • Both the `.custombox-overlay` and the `.custombox-modal-wrapper` highlight the scroll bar when I inspect those elements. – Patrick Gregorio Apr 04 '16 at 19:02
  • @PatrickGregorio But `.custombox-overlay` isn't a parent of the `.text` div (div which contains actual content of the modal), it doesn't have any children at all. – Michał Perłakowski Apr 04 '16 at 19:05