Index pages with anchor links to the various sections of the index are a very common website setup nowadays. Unfortunately the anchor links do not work correctly on mobile. In my case, when clicking an anchor link doesn’t close the menu and scroll to the correct section.
My idea of solution is to add a click event. When clicking the anchor link, the mobile navigation will close.
But this function still not work at my website. Can anyone tell me is that anything I did wrong?
My website: I-kinball.org (pw: treats)
reference website: riverstonedigital.com (mobile version)
This is the function I added:
<script>
//Anchor link fix
function anchorLinks(){
Y.all("a.Mobile-overlay-nav-item").on('click',function(){
Y.one('body').removeClass('is-mobile-overlay-active');
});
Y.all("a.Mobile-overlay-folder-item").on('click',function(){
Y.one('body').removeClass('is-mobile-overlay-active');
});
}
// DOM Ready
Y.on('domready', function(){
anchorLinks()
});
//RSD Mutation Boserver wrapper
function RSD_init(){
anchorLinks();
}
// add watch function to window.onload
window.onload = RSD_watch;
// watch function to look for page changes using Mutation Observer
function RSD_watch() {
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var mo = new MutationObserver(function(mo) {
var moCount = 0;
for (var b = 0; b < mo.length; b++) {
var c = mo[b];
if ("attributes" === c.type && moCount === 0) {
RSD_init();
}
}
});
var options = { attributes : true, attributeFilter : ['id']};
mo.observe(document.body, options);
}
</script>