I made an example of my problem in this jfiddle: https://jsfiddle.net/kLh8r294/2/
Here is the javascript:
$(document).ready(function() {
function close_accordion_section() {
$('.accordion .accordion-section-title').removeClass('active');
$('.accordion .accordion-section-content').slideUp(1000).removeClass('open');
}
$('.accordion-section-title').click(function(e) {
// Grab current anchor value
var currentAttrValue = $(this).closest('.accordion-section-title');
if(currentAttrValue.hasClass('active')) {
close_accordion_section();
}else {
close_accordion_section();
// Add active class to section title
currentAttrValue.addClass('active');
// Open up the hidden content panel
$('.accordion ' + currentAttrValue.attr('href')).slideDown(1000).addClass('open');
}
e.preventDefault();
});
});
Rest is on jsfiddle.
When i open an accordion and there is a lot of content, the content scrolls off screen. Now i made an example of "First one" and "Last one".
I want to make the focus stay on the accordion title for instance as it is opening, so when the content goes off screen, the user still has the beginning of the clicked accordion in focus. In case its a little bit off the focus of the accordion it should scroll smoothly to it not just jump in one go.
Is there anything already built in jquery or javascript that can be used? Im learning all of this as i go so any help would be appriciated, or insight.