Skip to content

Commit 9b0e1dd

Browse files
Feat: Implement hover-to-open navbar with animation (#1768)
1 parent f9c5c7b commit 9b0e1dd

File tree

3 files changed

+70
-3
lines changed

3 files changed

+70
-3
lines changed

_includes/navbar.ext

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
</li>
2727
<li class="dropdown">
2828
<a class="dropdown-toggle" data-toggle="dropdown" href="{{site.baseurl}}/index.html" id="meetings_menu"><span class="glyphicon glyphicon-phone-alt"></span>&nbsp;&nbsp;Meetings<span class="caret"></span></a>
29-
<ul class="dropdown-menu" aria-labelledby="activities_menu">
29+
<ul class="dropdown-menu" aria-labelledby="meetings_menu">
3030
{% for meeting in site.meetings %}
3131
<li><a href="{{ meeting.url }}">{{ meeting.title }}</a></li>
3232
{% endfor %}
33-
</ul>
33+
</ul>
3434
</li>
3535
<li class="dropdown">
3636
<a class="dropdown-toggle" data-toggle="dropdown" href="{{site.baseurl}}/index.html" id="communication_menu"><span class="glyphicon glyphicon-bullhorn"></span>&nbsp;&nbsp;Communication<span class="caret"></span></a>
@@ -67,7 +67,7 @@
6767
<li class="dropdown">
6868
<a class="dropdown-toggle" data-toggle="dropdown" href="{{ site.baseurl }}/index.html" id="about_menu"><span class="glyphicon glyphicon-info-sign"></span>&nbsp;&nbsp;About<span class="caret"></span></a>
6969
<ul class="dropdown-menu" aria-labelledby="about_menu">
70-
<li><a href="{{ site.baseurl }}/get_involved.html">Get involved!</a><li>
70+
<li><a href="{{ site.baseurl }}/get_involved.html">Get involved!</a></li>
7171
<li><a href="{{ site.baseurl }}/organization/team.html">The Steering Group</a></li>
7272
<li><a href="{{ site.baseurl }}/organization/advisory-group.html">HSF Advisory Group</a></li>
7373
<li class="divider"></li>

_layouts/default.html

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,49 @@
3535

3636
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
3737
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
38+
<!-- Navbar Hover Effect -->
39+
<script>
40+
$(document).ready(function() {
41+
42+
function applyDesktopNavbar() {
43+
// Turn on hover-open functionality
44+
$('ul.nav li.dropdown').hover(function() {
45+
$(this).addClass('open');
46+
}, function() {
47+
$(this).removeClass('open');
48+
});
49+
50+
// Disable the default click and remove focus styling on desktop
51+
$('.dropdown > a.dropdown-toggle').on('click.desktop', function(e) {
52+
e.preventDefault(); // Prevents the link from being followed
53+
e.stopPropagation(); // Stops the event from bubbling up
54+
$(this).blur(); // Removes the focus, getting rid of the yellow color
55+
});
56+
}
57+
58+
function removeDesktopNavbar() {
59+
// Turn off hover functionality for mobile
60+
$('ul.nav li.dropdown').off('mouseenter mouseleave');
61+
// Restore default click behavior for mobile
62+
$('.dropdown > a.dropdown-toggle').off('.desktop');
63+
}
64+
65+
// Check window size to apply the correct behavior
66+
function toggleNavbarBehavior() {
67+
if ($(window).width() > 767) {
68+
applyDesktopNavbar();
69+
} else {
70+
removeDesktopNavbar();
71+
}
72+
}
73+
74+
// Run the check once on page load
75+
toggleNavbarBehavior();
76+
77+
// And run it again whenever the window is resized
78+
$(window).on('resize', toggleNavbarBehavior);
79+
80+
});
81+
</script>
3882
</body>
3983
</html>

css/hsf.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,27 @@ figure.centered-figure {
414414
.big-link-container a {
415415
min-height: 0;
416416
}
417+
}
418+
/* Navbar Hover Effect */
419+
/* This applies the animation only to desktop-sized screens */
420+
@media (min-width: 768px) {
421+
.navbar-nav .dropdown-menu {
422+
/* Keep the menu in the document flow but make it invisible */
423+
display: block;
424+
opacity: 0;
425+
visibility: hidden;
426+
pointer-events: none; /* Prevent mouse interaction when hidden */
427+
428+
/* Animate the fade-in and slide-down effect */
429+
transform: translateY(-10px);
430+
transition: opacity 0.3s ease, transform 0.3s ease;
431+
}
432+
433+
/* When the .open class is added by our script, make the menu visible */
434+
.navbar-nav .dropdown.open > .dropdown-menu {
435+
opacity: 1;
436+
visibility: visible;
437+
pointer-events: auto; /* Allow mouse interaction */
438+
transform: translateY(0);
439+
}
417440
}

0 commit comments

Comments
 (0)