Foundation 6 Off-canvas menu auto-close after click

老子叫甜甜 提交于 2020-01-04 01:37:45

问题


I've been searching how to auto-close off-canvas menu after some menu item is clicked but nothing seems to work.

So I followed guide on how to make off-canvas menu on Foundation 6 docs and it works. This part is okay. Now when I click on some link menu just stays there and I want it to close. Does anyone know how to fix that.

I've found snippet that should do the trick but my menu stops showing after I appy this JS. Others report the same problem.

$(document).foundation({
  offcanvas : {
    open_method: 'move', // Sets method in which offcanvas opens, can also be 'overlap'
    close_on_click : true
  }
});

Here are the docs, but since I don't know much about JavaScript I beg someone to write correct code.


回答1:


You could use the close method on the .off-canvas menu when a link is clicked:

$('.off-canvas a').on('click', function() {
    $('.off-canvas').foundation('close');
});

Click Here for a demo.




回答2:


In advance, sorry for my poor english,

Just go through online to figure it out, and finally, the script above that Yass provided is working. But when i inserted Slick slider script in, it no longer worked.

i just found out a solution that worked for me, but maybe there have bug, dunno.

Inside foundation offcanvas documentation, a close button to close the canvas is given, like below showed.

<button class="close-button" aria-label="Close menu" type="button" data-close>
    <span aria-hidden="true">&times;</span>
</button>

So I adapted it and put the "data-close" to the link, when i clicked, it scroll to the specific div and close up canvas

And here is the link for more understanding? because i think my explanation sucks

https://jsfiddle.net/mbsj7d7p/



来源:https://stackoverflow.com/questions/35940367/foundation-6-off-canvas-menu-auto-close-after-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!