I am trying to open a modal window with a link and scroll to a specific DIV inside it.
HTML:
<a href="#teamMembers" data-toggle="modal" class="teamMemebrScroll1">read more</a>
<a href="#teamMembers" data-toggle="modal" class="teamMemebrScroll2">read more</a>
<a href="#teamMembers" data-toggle="modal" class="teamMemebrScroll3">read more</a>
<div class="portfolio-modal modal fade" id="teamMembers" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-content">
<div class="container" data-id="teamMemebrScroll1">....</div>
<div class="container" data-id="teamMemebrScroll2">....</div>
<div class="container" data-id="teamMemebrScroll3">....</div>
</div>
JS:
// scroll to team member 2
jQuery(document).ready(function ($) {
$(".teamMemebrScroll2").click(function (event) {
event.preventDefault();
$('html,body').animate({ scrollTop: $(this.hash).offset().top }, 1000);
});
});
Although the modal is opening correctly, I am encountering an issue where it always scrolls back to the top instead of the intended location.