[英]How do I animate a Bootstrap 4 sliding dropdown menu back up?
I'm new on here so I hope I can be as clear as possible with my problem:-)我是新来的,所以我希望我能尽可能清楚我的问题:-)
OK so, I'm working on a fairly simple dropdown menu in Bootstrap 4. There's quite a lot of code because I'm wanting to control every aspect of it, the way I've laid it out is fairly messy because this is testing phase, but hopefully you'll see it's fairly easy to get what's going on because I've put comments everywhere and labelled everything !好的,我正在 Bootstrap 4 中处理一个相当简单的下拉菜单。有很多代码,因为我想控制它的各个方面,我布置它的方式相当混乱,因为这是测试阶段,但希望你会看到它相当容易了解正在发生的事情,因为我已经将评论放在任何地方并标记了所有内容!
I'd like to use Animation to slide the NavBar Dropdown menu up and down with a toggle click.我想使用 Animation 通过单击切换来上下滑动导航栏下拉菜单。 I found a demo online using transitions, which works fairly well but is buggy on mobile.
我在网上找到了一个使用过渡的演示,效果很好,但在移动设备上存在问题。 The bug is that if you click the button to close after 3 seconds, the menu snaps shut instead of sliding shut.
错误是如果您在 3 秒后单击按钮关闭,菜单会突然关闭而不是滑动关闭。 It's meant to slide shut every time.
它的意思是每次都滑动关闭。 This seems to be a consistent bug from the examples I've seen.
这似乎是我见过的示例中的一致错误。
Therefore I'm trying out Animations instead, they can do more and I can have even more control over elements.因此,我正在尝试动画,它们可以做得更多,我可以对元素有更多的控制。
I've worked out how to use an animation to slide down the menu:我已经弄清楚如何使用 animation 向下滑动菜单:
CustomJQ('.dropdown').on('show.bs.collapse', function() { // Dropdown Menu button is in the transition process of sliding down //
CustomJQ(this).find(".dropdown-menu").first().removeClass('MonkeeClassAnimationDown')
CustomJQ(this).find(".dropdown-menu").first().addClass('MonkeeClassAnimationDown')
});
“MonkeeClassAnimationDown” is my animation class and works beautifully every time, opacity fades in and it slides down “MonkeeClassAnimationDown”是我的 animation class 并且每次都能很好地工作,不透明度淡入并向下滑动
Now the tricky part - I can't for the life me find the correct Bootstrap class or function to say, in Layman's terms: “When NavBar Menu Button is clicked again to toggle – remove the Animation Down class and add Animation Up class”. Now the tricky part - I can't for the life me find the correct Bootstrap class or function to say, in Layman's terms: “When NavBar Menu Button is clicked again to toggle – remove the Animation Down class and add Animation Up class”. The Up class I have ready and waiting, I just can't see how to apply it
Up class 我已经准备好等待,我只是看不到如何应用它
Here's the links:这是链接:
http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/ http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/
http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/_CustomCSS http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/_CustomCSS
http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/_CustomJavascripts/CustomJS.js http://tunedinevents.co.uk/__Testing/Top_NavBar_Dropdown_Menu/_CustomJavascripts/CustomJS.js
If anyone has cracked this, probably don't even need to view code….如果有人破解了这个,可能甚至不需要查看代码…… if you know the Bootstrap JS function that I can apply my Up Animation when toggle clicked, that'd be great !
如果您知道 Bootstrap JS function,我可以在单击切换时应用我的 Up Animation,那就太好了!
Hope I've been clear enough… thanks:-)希望我已经足够清楚了……谢谢:-)
I actually worked it out I'm pleased to say:-)我真的解决了我很高兴地说:-)
// SUB DROPDOWN MENU TITLE BUTTONS //
CustomJQ('.dropdown').on('show.bs.collapse', function() { // Dropdown Menu button is in the transition process of sliding down //
CustomJQ(this).find('.hide.bs.collapse').first().removeClass('MonkeeClassDelayClosingDropdownMenu');
CustomJQ(this).on('.dropdown').addClass('MonkeeClassTopMenuMainButtonClick'); // Unhighlight the Sub Menu Title //
CustomJQ(this).find('.dropdown-menu').first().removeClass('MonkeeClassAnimationUp');
CustomJQ(this).find('.dropdown-menu').first().removeClass('MonkeeClassAnimationDown');
CustomJQ(this).find('.dropdown-menu').first().addClass('MonkeeClassAnimationDown');
CustomJQ('.MonkeeClassNavBarBackground').removeClass('peru orange yellow lime plum olive indigo');
CustomJQ('.MonkeeClassNavBarBackground').addClass('olive');
});
CustomJQ('.dropdown').on('hide.bs.collapse', function() { // Dropdown Menu button has just finished the process of sliding up //
CustomJQ(this).find('.hide.bs.collapse').first().removeClass('MonkeeClassDelayClosingDropdownMenu');
CustomJQ(this).find('.hide.bs.collapse').first().addClass('MonkeeClassDelayClosingDropdownMenu');
CustomJQ(this).on('.dropdown').removeClass('MonkeeClassTopMenuMainButtonClick'); // Unhighlight the Sub Menu Title //
CustomJQ(this).find('.dropdown-menu').first().removeClass('MonkeeClassAnimationUp');
CustomJQ(this).find('.dropdown-menu').first().removeClass('MonkeeClassAnimationDown');
CustomJQ(this).find('.dropdown-menu').first().addClass('MonkeeClassAnimationUp');
CustomJQ('.MonkeeClassNavBarBackground').removeClass('peru orange yellow lime plum olive indigo');
CustomJQ('.MonkeeClassNavBarBackground').addClass('plum');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.