somewebmedia / hc-offcanvas-nav

JavaScript library for creating toggled off-canvas multi-level navigations, allowing endless nesting of submenu elements, supporting swipe gestures, keyboard interactions and ARIA attributes.
https://somewebmedia.github.io/hc-offcanvas-nav/
MIT License
336 stars 82 forks source link

Close nav is not on top of menu #59

Closed maddorris closed 3 years ago

maddorris commented 3 years ago

Hi,

one small issue i can't fix - close button appearing on the second place right after Home menu link. Do you have probably any idea what could cause it?

Nav title

Home

Close

Other nav item

etc

Back button after you click deeper is then on the right place.

Thanks in advance for any support.

maddorris commented 3 years ago

Update - it's not a bug its a feature: insertClose: 0 solves the issue =)

maddorris commented 3 years ago

One question i have - is it possible to open menu on current active page level and not each time from start?

Thanks.

somewebmedia commented 3 years ago

Yes, check the data-nav-active attribute.

If you're using WordPress I've wrote a out of the box working code.

maddorris commented 3 years ago

Thank you. Ill check on this. Im Working basicaly with joomla, but i think i will get this working =)

maddorris commented 3 years ago

Unfortunately it didnt work for me. so i was able to add data-nav-active to last active li-element, but it still open from start. So my structure is now like

<ul>
   <li>menu 1<7li>
   <li> menu 2 
      <ul>
          <li data-nav-active>Menu 2.1</li> 
     </ul>
    </li>
</ul>

May it be an issue adding this data attribute via jQuery and not directly in code?

$(function(){ $('ul.menu li.active').last().attr('data-nav-active',''); });

Any help is very appreciated =)

somewebmedia commented 3 years ago

Try it like this:

<ul>
   <li>menu 1<7li>
   <li data-nav-active> menu 2 
      <ul>
          <li>Menu 2.1</li> 
     </ul>
    </li>
</ul>

And if you're using jQuery to add the attribute, be sure to add it before initiating the Nav.

maddorris commented 3 years ago

Hi, thanks for advise, but unfortunately this didnt woked for me.

I did tryed to add data-nav-active to current active li, to his ul-parent or to ul-li-parent - all of this didnt worked.

I did checked hc-offcanvas-nav.js and didnt found any implementation for data-nav-active and data-nav-highlight. Can it be this is not inplace in git-version? Cause id did tryed same on your demo also and wasn't lucky as well...

Thanks for your support.

somewebmedia commented 3 years ago

I've just noticed how you are using jQuery attr() to add attribute. You must use it like this .attr('data-nav-active', true)

maddorris commented 3 years ago

I do it like: $("#main-nav ul.menu li.active.parent:last").attr("data-nav-active","");

And adding this attribute works very well. But it doesnt affect how the nav is working.

somewebmedia commented 3 years ago

So, have you tried using the true instead of ''?

maddorris commented 3 years ago

This doesnt help. What i noticed - your script create a clone of original navigation and hide the origin one. So i have two navs - hidden and one created by script. In origin i see all by system or via script added attributes and Id's. In cloned nav all these are missing. I gues this is the reason why it doesnt work.

Hovever i cant add id or data attributes to cloned nav, cause i have to do it before it will be initialized, as you told.

Thank you

somewebmedia commented 3 years ago

In cloned nav all these are missing. I gues this is the reason why it doesnt work.

Nope this is as it should be. Something else is troubling you.

I've just checked the data attributes with the repository demo and everything works as expected. So in order to help you, you would have to provide me with some demo I can live test.

maddorris commented 3 years ago

did send you via mail.

somewebmedia commented 3 years ago

For anyone reading, the problem was caused by the usage of the much older version of the plugin.