Displaying a dropdown menu from the top by utilizing the show() function

I've successfully implemented a dropdown menu using cssmenumaker. It works perfectly on desktop and mobile view. However, I'm facing an issue on mobile where the dropdown menu slides in from the left when clicked. I would prefer it to slide down from the top instead. While I'm not well-versed in jQuery, here is the code snippet I am currently using:

Here is the live link: live link

/*================ Menu ====================*/
(function($) {

    $.fn.menumaker = function(options) {
        var cssmenu = $(this), settings = $.extend({
            title: "Menu",
            format: "dropdown",
            sticky: false
        }, options);

        return this.each(function() {
            cssmenu.prepend('<div id="menu-button">' + settings.title + '</div>');
            $(this).find("#menu-button").on('click', function(){
                $(this).toggleClass('menu-opened');
                var mainmenu = $(this).next('ul');
                if (mainmenu.hasClass('open')) {
                    mainmenu.hide().removeClass('open');
                }
                else {
                    mainmenu.show("slow").addClass('open');
                    if (settings.format === "dropdown") {
                        mainmenu.find('ul').show("slow");
                    }
                }
            });

            cssmenu.find('li ul').parent().addClass('has-sub');

            multiTg = function() {
                cssmenu.find(".has-sub").prepend('<span class="submenu-button"></span>');
                cssmenu.find('.submenu-button').on('click', function() {
                    $(this).toggleClass('submenu-opened');
                    if ($(this).siblings('ul').hasClass('open')) {
                        $(this).siblings('ul').removeClass('open').hide();
                    }
                    else {
                        $(this).siblings('ul').addClass('open').show("slow");
                    }
                });
            };

            if (settings.format === 'multitoggle') multiTg();
            else cssmenu.addClass('dropdown');

            if (settings.sticky === true) cssmenu.css('position', 'fixed');

            resizeFix = function() {
                if ($( window ).width() > 767) {
                    cssmenu.find('ul').show("slow");
                }

                if ($(window).width() <= 767) {
                    cssmenu.find('ul').hide().removeClass('open');
                }
            };
            resizeFix();
            return $(window).on('resize', resizeFix);
        });
    };
})(jQuery);

(function($){
    $(document).ready(function(){

        $("#cssmenu").menumaker({
            title: "",
            format: "multitoggle"
        });

    });
})(jQuery);

Answer №1

Experiment using the slideDown(); method instead of the show(); function.

Answer №2

Opt for slideDown() instead of show()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

`Arc canvas countdown timer`

My countdown timer created using canvas is functioning well, but I am encountering some issues: I would like to align the circle representing seconds with the circles for minutes, hours, and days similar to this demo. Please ensure running the code snipp ...

Animating a 3D object along a path in Three.js

I am trying to shoot a projectile from one mesh to another. I connected them with a line, but now I'm struggling to move the projectile along this path. The translateOnAxis function didn't seem to do the job. Do you have any suggestions for how ...

How can I implement a CSS property on a child class when the parent class is toggled on and off?

Looking to style a child div within a parent div that toggles classes based on a flag. The parent div can have either the .pricing-section or .new-pricing-section class. Here's the structure of the parent div: const togglePriceSection = isPricingDetai ...

Display the chosen option's value with PHP - Nothing Else

I am new to PHP and encountering an issue with my project. I have created a database that contains a "members" table with columns for "member_id" and "member_name". I've also set up a select box populated with members' names. My goal is to echo t ...

Ways to select elements from an array of objects based on date

I'm currently working on a task that involves filtering an array of objects to find the ones closest to today. Unfortunately, I encountered an issue where the code is returning dates in June instead of May. Here's the snippet of code I've be ...

The navigation bar is obscuring the header on my website

I am facing an issue with creating a navigation bar that covers up the header text. I tried adjusting the margins to fix this problem but ended up moving the header along with the navigation bar. How can I ensure that the navigation bar remains fixed witho ...

Enable users to retrieve files generated through ajax calls

Recently, I've been using PHPWord to dynamically generate MS Word documents in my PHP project. Everything is working smoothly so far - I can successfully create a file and save it on my server through an ajax request. However, once the document is gen ...

I recently installed bootstrap, jquery, and popper.js on my live server, but to my surprise, nothing was appearing on the screen. Despite compiling the

After successfully installing bootstrap, jquery, and popper.js, I encountered an issue on my live server where nothing was displaying. Oddly enough, no errors were detected after compiling the code. import { createApp } from 'vue' import App from ...

Refresh the custom JavaScript dropdown list without having to reload the page

I implemented this code to customize a drop-down list Selector. Is there a way to reset this code without reloading the page, maybe by triggering a function with a button click? <button onclick="reset();">Reset</button> For example, if "Jagu ...

Exploring the process of traversing a function for each ng-repeat element

Hey everyone, I'm currently facing an issue where I need to pass each date through a function in order to get the desired result. Let's take a closer look at the code snippet: <md-list> <md-divider ></md-divider> ...

Learn how to transform the default arrows in vis.js into quirky chicken feet or elegant cardinality symbols

I'm exploring the possibility of using vis.js to visually represent the structure of an XML or JSON Schema. Instead of arrows, I want to display cardinality information. Does anyone have recommendations for documentation that can help me with this? I ...

Is it possible to restrict the movement of the dialog to stay within the boundaries of the window

html: <div id="dialog" title="Past Issues"> </div> Jquery: $( "#dialog" ).dialog({ height: 900, width:1200, modal: true, }); Currently facing an issue where the dialog can be dragged outside of the window are ...

Python Selenium returning 'None' when attempting to retrieve the source attribute of an image

Having trouble retrieving the src of images in the class "KfFlO" using selenium. Whenever I try to print for the source, Python keeps returning "none." Can anyone help me identify the problem? Below is my code snippet: from selenium import webdriver from s ...

Press the submit button after receiving the ajax response

Is there a way to manually or programmatically submit a specific page? The catch is that before the submission can happen, a function called create_impi_num(x) needs to be triggered in order to store data using $.post(). The issue at hand: If I set the s ...

Troubleshooting Bootstrap 5 Navbar Customization Problem: Vertical Display Instead of Horizontal Viewing

My current challenge involves customizing a Bootstrap 5 navbar to arrange three elements - a user avatar, a notifications panel, and a menu icon - in a horizontal layout. Despite my efforts, these elements are appearing in a vertical stack instead of horiz ...

"Utilizing jQuery to extract an object from an external JSON file and

I have an API that returns JSON data. You can see a simple example of this in the image linked below: View screenshot with JSON example My goal is to add objects from the JSON response to an array, similar to the following example: [{title: 'Marker ...

Python code that extracts data from an AJAX website

Looking to scrape a website that includes a directory of individuals and their details. The issue arises when the site uses ajax to load new information as I continue scrolling down. I'm in need of data for every single person on the list. The urllib ...

What is the best way to utilize useRef on a component that is not accessible within React BigCalendar?

I'm currently working with React Big Calendar (https://github.com/intljusticemission/react-big-calendar) and facing a challenge with responsive styling. I need to detach the horizontal scrollbar (overflow-x) of a specific div, .rbc-agenda-view, and at ...

Is event delegation in React similar to jQuery's `on()` method?

Just starting out with React.js and I've built a list Component that has items being added and removed frequently. Each item needs to have click and/or hover events. I'm looking to implement event delegation similar to how it's done in jQue ...

The load event in React's iframe is failing to fire after the src attribute is modified using state

In the process of creating a registration form for a React application, we encountered the need to incorporate an HTML legal agreement as an iframe. This legal document is available in various languages, one of which can be selected using a drop-down menu; ...