Is there a way to force the dropdown to close when linking to sections on the same page. I made a simple example here http://nav-tester.webflow.com/
The dropdown menu should close when you click one of the links. Is this working as intended?
Is there a way to force the dropdown to close when linking to sections on the same page. I made a simple example here http://nav-tester.webflow.com/
The dropdown menu should close when you click one of the links. Is this working as intended?
Hi @Will_Specht, at the moment, the Drop Down widget does not auto close after click, however the Nav Bar Widget does auto close, so if you need this, you can use the Nav Bar, and set the Nav Bar to to show the Drop Down for all viewports (desktop, tablet, landscape phone and portrait phone) It is a good suggestion to have this close on click, so we will look at that and see about adding this in an upcoming update.
Cheers, Dave
Hello,
While working on my site, I also needed the same feature. After various attempts and hacks on the webflow designer
I saw that it is not possible at the moment so I prepared a full zip and edited the webflow.js.
The below code works for me, my dropdown now closes when I click on dropdown items, the toggle or outside.
In webflow.js find the following function under the dropdown components section and add those lines:
if($target.closest('.w-dropdown-link'))
{
close(data);
}
sample is belowâŚ
function outside(data) {
// Unbind previous tap handler if it exists
if (data.outside) $doc.off('tap' + namespace, data.outside);
// Close menu when tapped outside
return _.debounce(function(evt) {
if (!data.open) return;
var $target = $(evt.target);
if ($target.closest('.w-dropdown-toggle').length) return;
if (!data.el.is($target.closest(namespace))) {
close(data);
}
if($target.closest('.w-dropdown-link')) {
close(data);
}
});
}
Hi @Tolga_Inam, Thanks for sharing
@danro, check this out
Only downside is, you can not check in designer.
Would be nice, if this could be done via the API. Something like $(â.w-dropdownâ).data(â.wDropdownâ).close()
Sweet! Thanks. Works well for me.
Would be great if this was in designer. This issue arises when using a dropdown with anchor links in a scrolling site.
Iâve implement but unfortunately this is causing issues on mobile for me. (tested on iPhone 4s, 5s, and 6 only)
A couple of things happen:
Working on a solution to only effect the desktop menu and not the mobile menu. Will post if I figure something out.
this seems to have taken care of the mobile dropdown weirdness:
if (Modernizr.touch || winMobileCheck === true) {
//this is a mobile device
} else {
if($target.closest('.w-dropdown-link')) {
close(data);
}
}
});
}
Hi everyone,
Iâve got this exact same problem. The scroll site that Iâm designing consists of a menubar with three dropdown lists which corresponds to three different pages. These lists are opened on hover. The different items in each list is linked to a section of each page. So when a link is clicked and the page scrolls down to a said section the dropdown list covers the heading of that section. Very annoying and not very intuitive for the visitor.
Iâve tried copying the code @Tolga_Inam provided into the Footer code for the entire site but canât det it to work.
What I want is essentially a piece of code that makes the menu dropdown close when a link in it is clicked.
Is there any new progress on this?
Would really appreciate it!
Thanks,
Daniel
Hey @catino thereâs also now an option for drop down menus to open on hover instead of click, if you look in the settings tab youâll see a checkbox for it now which solves this problem for the most part. if not I have some custom code which works for this as well.
Hi @Waldo
Thanks for your reply! Iâm aware of this option but alas it doesnât solve our problem. With âOpen on hoverâ switched on the menu still doesnât close down after I click the link. Not on desktop nor mobile.
Just to clarify, the link Iâm clicking is in a dropdown list in the menu and it refers to a section on the same page.
The problem is biggest on mobile, where the menu cover a bigger portion of the screen and thus covers more content. So when you click the hamburger and open the menu, click a dropdown to expand it, and then click a link, the window scrolls down slightly to the referred section, but the menu is still out and covers everything.
Hope thereâs a solution for this!
Daniel
Hey @catino
This should work for you, just paste it in the footer area of your site :
<script>
$("a").click(function(){
$("nav").removeClass("w--open");
});
$("a").click(function(){
$("div").removeClass("w--open");
});
</script>
Thanks @Waldo! That works really well for desktop! Mobile still doesnât work thoughâŚ
Is there a way to make this code affect the mobile menu as well? We had to use a separate menu to get other functions to work so our mobile menu is a separate object, only visible on mobile and always with the âhamburgerâ button.
Thanks for looking at this for us me!
/Daniel
Hi @cyberdave. Back in August 2014 you had mentioned that you guys would look into adding âclose on clickâ for the Dropdown widget â is this still the plan? Ta.
Hi @spincinconi, thanks for giving this topic some CPR I will need to check on this. If there is not a feature request already made, I will ensure that it gets some attention. As soon as there is more info on this, I will update.
Many thanks, @cyberdave. Looking forward to an update. Cheers.
For mobile, see my reply in this thread from Jul 2015
hello. i tried pasting this code in an embed element in what would be the footer element of my page. however, nothing seems to have changed. some more explicit instructions would be really helpful. i very much need this to work. thanks!
Hi @cyberdave
Old post, but I give the topic a bit more CPR, since itâs a very useful feature! Any news?
Edit: I see now with some more testing that this actually works if I use the built in âLink to sectionâ feature. But since I often link to sections on different pages and thereby have to use the ââŚ/#sectionâ link hack, it does not work
I have added it to my ultimate wish list too