ons-sliding-menu: active item



  • What a simple way is to determine “active item” in the ons-sliding-menu?
    I need this to add a class and add “prevent repeating clicks” if current page is open(it’s breaks my script). I have been checking code, forum, doc already

    hm… maybe simple is add “toggle class”



  • @Евгений-Гедройц The simplest way would be to dynamically add/change the CSS class and mark the link as active. You would also be able to disable the onclick event thus preventing double fires. So your two classes, active and notactive, are css that enables the link and disables it as well.

    var activeLink = '';
    function setActive(newLink) {
       document.getElementById(activeLink).className='notactive';
       document.getElementById(newLink).className='active';
       activeLink=newLink;
    }
    


  • @munsterlander thank you for reply, but sliding menu not change location.href
    It’s Single Page Application without history api. “Preventing double fires” is not enough for this i suppose, if i’ll need to click from other pages, but i’ll try disable the onclick



  • @Евгений-Гедройц Updated the code to reflect the easiest possible way to pull this off that I can think of.