Skip to content

Instantly share code, notes, and snippets.

@AlphaAlec
Last active November 24, 2015 05:14
Show Gist options
  • Save AlphaAlec/c235d47a6951ac8160c8 to your computer and use it in GitHub Desktop.
Save AlphaAlec/c235d47a6951ac8160c8 to your computer and use it in GitHub Desktop.
WP Menu Item Count for Mobile Menu Transitions
<?php
// you can get the menu by name, ID, slug or location
$menu_count = wp_get_nav_menu_object( 'Main Menu' ); // here we're grabbing it by name
$menu_count = $menu_count->count
?>
<style type="text/css">
<?php for($i = 1; $i <= $menu_count; $i++) { ?>
<?php $delay = $i * 0.033; ?>
#mobile-nav li:nth-of-type(<?php echo $i; ?>) {
-webkit-transition-delay: <?php echo $delay; ?>s;
-moz-transition-delay: <?php echo $delay; ?>s;
-o-transition-delay: <?php echo $delay; ?>s;
transition-delay: <?php echo $delay; ?>s;
}
<?php } ?>
</style>
<?php // assuming your menu count was four, this is what the CSS/PHP combo would output ?>
<style type="text/css">
#mobile-nav li:nth-of-type(1) {
-webkit-transition-delay: 0.033s;
-moz-transition-delay: 0.033s;
-o-transition-delay: 0.033s;
transition-delay: 0.033s;
}
#mobile-nav li:nth-of-type(2) {
-webkit-transition-delay: 0.066s;
-moz-transition-delay: 0.066s;
-o-transition-delay: 0.066s;
transition-delay: 0.066s;
}
#mobile-nav li:nth-of-type(3) {
-webkit-transition-delay: 0.099s;
-moz-transition-delay: 0.099s;
-o-transition-delay: 0.099s;
transition-delay: 0.099s;
}
#mobile-nav li:nth-of-type(4) {
-webkit-transition-delay: 0.132s;
-moz-transition-delay: 0.132s;
-o-transition-delay: 0.132s;
transition-delay: 0.132s;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment