简体   繁体   English

单击下拉按钮时更改下拉动画的行为

[英]Changing behavior of dropdown animation when clicking through dropdown buttons

My dropdown menu currently works fine, but is there a way to change the behavior of the animation if another button on a dropdown menu is clicked. 我的下拉菜单目前可以正常工作,但是如果单击了下拉菜单上的另一个按钮,则有一种方法可以更改动画的行为。

For example, clicking on a menu button drops down a menu, but while that menu is open, you click on a second button that instead of dropping down like it normally would if none of the menus were open, slides in from the right while the menu that was previously click slides out to the left. 例如,单击菜单按钮会下拉菜单,但是当该菜单打开时,您单击的是第二个按钮,而不是像在没有菜单打开的情况下那样通常那样下拉,而是在菜单打开时从右侧滑入。先前单击的菜单向左滑动。 Similar to how theverge.com dropdown menu acts. 与theverge.com下拉菜单的操作类似。

<div  class="menu1"> 

<div class="menu1Container"><p class="menu1TextContainer">BUTTON1</p></div>

<div id="menu1Dropdown"> 

</div>

</div>

This is just the basic structure of each menu, which counts up. 这只是每个菜单的基本结构,其数量是最多的。

Furthermore, this is the jquery that initiates the dropdown 此外,这是启动下拉列表的jQuery

$(function() {

// Dropdown toggle
  $('.menu1Container').click(function(){
  $(this).next('#menu1Dropdown').slideToggle(100);
  });

$(document).click(function(e) {
    var target = e.target;
 if (!$(target).is('.menu1') && !$(target).parents().is('.menu1')) {
 $('#menu1Dropdown').slideUp(100);
 }
 });

});

https://jsfiddle.net/9j3k61rg/8/ https://jsfiddle.net/9j3k61rg/8/

thanks 谢谢

You would need to just set up a condition around your animations that looks to see if the other menu is open. 您只需要在动画周围设置一个条件即可查看其他菜单是否打开。 Something like this: 像这样:

if ($(".menu1Dropdown").css("display") == 'none') {
    // do my normal animation to menu 2
} else {
    // do some other animation to menu 2
}

Also I notice that you're using slideDown animation. 我也注意到您正在使用slideDown动画。 There is no slideLeft or slideRight but you can add that sort of functionality with jQueryUI, or you could use CSS transitions and just use Javascript to add and remove classes instead of setting css properties directly. 没有slideLeft或slideRight,但是您可以使用jQueryUI添加这种功能,或者可以使用CSS过渡,而仅使用Javascript添加和删除类,而不必直接设置css属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM