I am using the Jquery Toggle() function like this:
$("#btnbag1a").click(function(){
$("#bag1a").toggle();
});
It opens and shuts like a charm. Unfortunately, each time I use the button, it takes me to the top of the page, and I have to scroll down to see what was opened. Very poor UX.
I am using materializecss and wonder if their code is causing this problem.
Is there a way to make the show/hide keep the content in view? I tried adding this windown.location snippet to it and it did not work; it still went to the top of the page:
$("#btnbag1a").click(function(){
$("#bag1a").toggle();
window.location.assign('#bag1a');
});
A fuller sense of this code is in Wordy Jquery toggle
Could the following code be integrated in some way? It is used to open the accordion then scroll to the top of the accordion contents:
$(document).ready(function(){
$('.collapsible').collapsible({
accordion : false // A setting that changes the collapsible behavior to expandable instead of the default accordion style
});
$('.collapsible-header').bind('click',function(){
var self = this;
setTimeout(function() {
theOffset = $(self).offset();
$('body,html').animate({ scrollTop: theOffset.top - 100 });
}, 310);
});
});