javascript - My clickable jQuery drop-down menu does not work -


i've made clickable drop-down menu using jquery.

the drop-down menu must work like:
1) 'a' dropdown toggle click, 'a' dropdown menu visible
2) not('a' dropdown toggle , 'a' dropdown menu) === dropdownmenu hide
3) settimeout need(i'm code animation css)

i want multiple drop-down menus.

a, b, c, d...and "z"


but drop-down menu gives problem:
1) drop-down toggle click, after b drop-down toggle click === drop-down not hide
2) code not include document.closeset(i want include dropdowntoggle.click(function ()<<<

how can go clear issue? highly appreciated.

$(function(){    	body = $('body');      /* dropdown */    var dropdown = $('.dropdown'),        dropdowntoggle = dropdown.find('.toggle'),        dropdownmenu = dropdown.find('.menu'),        checkdropdownopen = 'close';        dropdowntoggle.click(function() {      $(this).each(function() {              // setinitial        var thisdropdown = $(this).parent('.dropdown'),            thisdropdowntoggle = $(this),            thisdropdownmenu = $(this).next('.menu');          // checkdropdownmenu = open        if (!thisdropdownmenu.hasclass('open') && (thisdropdownmenu.attr('aria-hidden') === 'true' || thisdropdownmenu.attr('aria-hidden') === undefined)) {                  // visible          settimeout(function() {            checkdropdownopen = 'open';            thisdropdownmenu.addclass('open');          }, 10);            // attr change          settimeout(function() {            thisdropdownmenu.attr('aria-hidden', 'false');          }, 218);         } else if (thisdropdownmenu.hasclass('open') && thisdropdownmenu.attr('aria-hidden') === 'false') {          // visible          settimeout(function() {            checkdropdownopen = 'close';            thisdropdownmenu.removeclass('open');          }, 10);            // attr change          settimeout(function() {            thisdropdownmenu.attr('aria-hidden', 'true');          }, 218);         }      })    });        /* dropdownclose() */    function dropdownclose() {      // toggle      dropdownmenu.removeclass('open');        // hidden, attr change      settimeout(function() {        body.removeclass('account-open');        dropdownmenu.attr('aria-hidden', 'true');      }, 218);    }        /* document click */    $(document).click(function(e) {      // dropdown      if (!$(e.target).closest(dropdown).length) {        dropdownclose();      }    });   });
.dropdown .menu {    display: none;  }    .dropdown .menu.open {    display:block;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="dropdown">    <button class="toggle">button</button>    <div class="menu">article</div>  </div>    <div class="dropdown">    <button class="toggle">button</button>    <div class="menu">article</div>  </div>

using existing code, add line:

dropdownclose(); 

between these lines:

dropdowntoggle.click(function() { $(this).each(function() {  

this close entire menu before opening target sibling menu.

another way same thing:

$( document ).ready(function() {   $('.toggle').on('click', function() {     $('.menu').hide(250);      $(this).next().show(500);   }); }); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -