mercredi 26 février 2020

Auto collapse sidebar menu list when lost focus

I am creating a modern admin panel for my site. I've got a sidebar menu that uses an accordion menu with jQuery. What I want to know is:

  1. How to auto collapse when mouseout and expand when mouseover on sidebar?
  2. How to expand it again when sidebar have class active/expand

I wrote a jQuery script but I don't have any idea with the problem above. Can someone help?

/*
 I want code that sidebar menu that have class `aktif` is expand when mouseIn Event
 And collapse again when mouseOut Event (hover event)
 Last i want `active menu` expand when sidebar toggle activated
*/

$(document).ready(function() {
  // Sidebar Menu Accordion
  $('.sidebar .side-list li a').on('click', function() {
    const $this = $(this);

    if ($this.parent().hasClass('buka')) {
      $this.parent().children('.dropdown-menu').slideUp(200, () => {
        $this.parent().removeClass('buka');
      });
    } else {
      $this.parent().parent().children('li.buka').children('.dropdown-menu').slideUp(200);
      $this.parent().parent().children('li.buka').children('a').removeClass('buka');
      $this.parent().parent().children('li.buka').removeClass('buka');
      $this.parent().children('.dropdown-menu').slideDown(200, () => {
        $this.parent().addClass('buka');
      });
    }
  });

  // ٍSidebar Toggle
  $('.burger').on('click', e => {
    $('.konten').toggleClass('k-kebuka');
    $('.sidebar').toggleClass('s-kebuka');
    e.preventDefault();
  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>



Aucun commentaire:

Enregistrer un commentaire