I have a function with which, when I click on a button, .section-down-arrow-wrapit will navigate through the ancestors and find the nearest element .fullscreen, the idea is when you click on it, it scrolls the element .sectionto the next instance .fullscreen, as you can see if this fiddle: https: //jsfiddle.net/neal_fletcher/d9zbw1k2/ , it does not work properly, some scroll you to the next one, some do not, some scroll you up. I need a method that will find fullscreenfurther down the tree, since it will not always be a grandparent element section-down-arrow-wrap. Here's the markup:
HTML:
<div class="section">
<div class="fullscreen"> <span>
<div class="section-down-arrow-wrap scroller">CLICK</div>
</span>
</div>
<div class="fullscreen">
<div class="half-screen">
<div class="section-down-arrow-wrap scroller">CLICK</div>
</div>
</div>
<div class="fullscreen"> <span>
<div class="section-down-arrow-wrap scroller">CLICK</div>
</span>
</div>
<div class="fullscreen">
<div class="half-screen">
<div class="section-down-arrow-wrap scroller">CLICK</div>
</div>
</div>
</div>
jQuery:
$(document).ready(function () {
$('.section-down-arrow-wrap.scroller').on('click', function () {
var fuller = $(this).closest('.fullscreen').next('.fullscreen'),
section = $(this).closest('.section');
section.animate({
scrollTop: fuller.offset().top + 0
}, 700);
});
});
Any suggestions would be greatly appreciated!