Skip to content

Instantly share code, notes, and snippets.

@Qwans
Last active September 15, 2021 13:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Qwans/92d813b94076f867e2d52c3121a2a5b3 to your computer and use it in GitHub Desktop.
Save Qwans/92d813b94076f867e2d52c3121a2a5b3 to your computer and use it in GitHub Desktop.
[Flatsome] Dark overlay on menu items with children
1. Add code below to your functions.php in your child theme.
add_action('wp_footer', 'qwans_add_darkness_dropdown');
function qwans_add_darkness_dropdown (){
echo '<div class="darkness"></div>';
};
2. Add CSS
.darkness {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0;
visibility: hidden;
background-color: rgba(0,0,0,.7);
-webkit-transition: opacity 0.25s ease,visibility 0s ease 0.25s;
transition: opacity 0.25s ease,visibility 0s ease 0.25s;
}
.darkness-opened {
opacity: 1;
visibility: visible;
-webkit-transition: opacity 0.25s ease,visibility 0.25s ease;
transition: opacity 0.25s ease,visibility 0.25s ease;
}
3. Add script below trough flatsome->advanced->global settings->footer script
<script>jQuery(document).ready(function($) {
$( '.menu-item-has-children' ).on('mouseover', function(e) {
if ( $(window).width() < 1024 ) return;
e.preventDefault();
if (!$('.menu-item').hasClass( '.has-dropdown' ) ) {
$('.darkness').addClass('darkness-opened');
}
});
$( '.menu-item.has-dropdown' ).on('mouseleave', function(e) {
if ( $(window).width() < 1024 ) return;
e.preventDefault();
if (!$('.menu-item').hasClass( '.has-dropdown' ) ) {
$('.darkness').removeClass('darkness-opened');
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment