Slide in the Toggle Effect to Your Navigation Menu

Seeking help with enhancing my jQuery dropdown menu to include a slide down toggle effect similar to this example: http://jsfiddle.net/LaSsr/188/. Any assistance in applying this slide effect to the following JSfiddle would be greatly appreciated. Thank you :)

JSFIDDLE

https://jsfiddle.net/6mWZa/182/

(function($, undefined) {
  var open = [];

  var opts = {
    selector: '.dropdown',
    toggle: 'dropdown-toggle',
    open: 'dropdown-open',
    nest: true
  };


  $(document).on('click.dropdown touchstart.dropdown', function(e) {
    // Close the last open dropdown if click is from outside the target dropdown
    if (open.length && (!opts.nest || !open[open.length - 1].find(e.target).length)) {
      open.pop().removeClass(opts.open);
    }

    var $this = $(e.target);

    // If target is a dropdown then toggle it...
    if ($this.hasClass(opts.toggle)) {
      e.preventDefault();

      $this = $this.closest(opts.selector);

      if (!$this.hasClass(opts.open)) {
        open.push($this.addClass(opts.open));
      } else {
        open.pop().removeClass(opts.open);
      }
    }
  });

})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="language" class="dropdown">
  <a href="#language" class="dropdown-toggle">English</a>
  <div class="dropdown-menu">
    <div class="dropdownCool">
      Hello1
    </div>
  </div>
</div>

<div id="locale" class="dropdown">
  <a href="#locale" class="dropdown-toggle">
        
        London</a>
  <div class="dropdown-menu">
    <div class="dropdownCool">
      Hello2
    </div>
  </div>
</div>

Answer №1

If you're struggling to find a solution, take a look at this:

/* dropdown */
.dropdown-menu {
    position:absolute;
    top:50px;
    right:0;
    left:0;
    display
    margin:0;
    padding:0;
    width:100%;
    list-style-type:none;
    width:100%;
    background-color:red;
   height:0px;
   transition:  height 0.15s ease-out;
   overflow: hidden;
}

Incorporate this into your .dropdown-menu class and

.dropdown-open > .dropdown-menu {

          height: 400px;
        transition:  height 0.25s ease-in;
    }

I removed the display none from the style and added height 0 and overflow:hidden for better visibility.

Please review your updated fiddle here.

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

An Exciting Adventure with the jQuery UI Datepicker: Embarking

Recently, I encountered an issue while attempting to clone and append a HTML table row. Within the row, there is a start date field that requires the jQuery UI datepicker functionality. Despite my efforts, I have been unable to successfully implement it. ...

Discover the method for concealing a button using ng-show and ng-hide directives

<div> <div class="pull-right"> <button type="button" data-ng-click="editFigure()" id="EditFigure">Edit Figure </button> <button type="button" data-ng-click="figurePreview()" id="PreviewFigure">Figure Previ ...

AngularJS templateUrl versus template: what's the difference?

When it comes to routing, I believe that templateUrl is the preferred choice over template. However, when dealing with directives, the decision between using templateUrl or template can be a bit more nuanced. Some developers opt to include chunks of HTML i ...

JavaScript - Ensure all special characters are maintained when using JSON.parse

I have encountered an issue while running a NodeJS app that retrieves posts from an API. The problem arises when trying to use JSON.parse on text containing special characters, causing the parsing process to fail. Special characters can include symbols fr ...

Discover the secrets to acquiring cookies within a Next.js environment

I am currently working with Next.js and attempting to retrieve a cookie value. Below is the code I have written: import cookie from "js-cookie"; export default function Home({ token }) { return ( <div className="flex flex-col items ...

How can I eliminate the padding from an image button in Bootstrap 5?

I am facing an issue with removing padding from a button that has an image inside it. I have tried using style="padding: 0px !important" and the p-0 class, but it doesn't seem to work. Switching the <button> to <a> removes the padding, but ...

What do you believe to be superior: Vue UI design?

Scenario: Application managing multiple user roles. A view with extensive conditional rendering in the template. a) Is it preferable to have numerous conditional statements in a single view's template? b) Should separate views be created for each ro ...

How can we wrap the Vuex store within a Vue plugin's install function?

I developed a plugin that utilizes Vuex for state management. // plugin.js import Vuex from "vuex"; import store from "./store.js"; export default { install(Vue, options) { const storeInstance = new Vuex.Store(store); Vue.pr ...

Getting base64 data from Node.js and showcasing it with jQuery

I have a scenario in which I store images or other types of files in my database as a blob. When retrieving that blob, I convert it to base64 by putting it in a buffer like this: file = Buffer.from(blob,'binary').toString('base64'); re ...

Tips for aligning two divs side by side: Ensure one of the divs is centered within the container that holds both divs

How would you align two divs next to each other, with one of them centered within the container? I'm trying to figure out how to position the second div right beside the first one and have it expand to the right. Any ideas? Check out this example : ...

Calculate the sum of hours worked in a day using pure JavaScript, no external libraries required

Hello, I'm new to this website and please excuse me if my English is not perfect, I am trying my best to communicate :) I have been working on a page that calculates the total hours worked in a day and this is what I have achieved so far until 15/06 ...

Looping through components using the render template syntax in Vue3

Below is my Vue3 code snippet: <template> {{click}} <ol> <li v-for="item in items" :key="item" v-html="item"></li> </ol> </template> <script setup> const click = ref(); const items = ...

Adding an object to an array using the Array.push() method deposits an array

Currently, I am extracting the days of absence of my colleague from excel files and storing them in a MongoDB database using Mongoose and Express.js. The process of reading the data is smooth; however, when trying to update the data in the database, an un ...

The <a> tag is failing to cover the appropriate section of the <div> element

I am facing the following issue: HTML: <div id="about" class="menu1"> <a href="#">About</a></div> <div id="aboutsub"> <div id="team" class="menu2"> <a href="">Team</a></div> &l ...

What steps can be taken to deter users from repeatedly liking comments, similar to the systems seen on Facebook or YouTube for like/dislike features?

I am currently working with express, react, and MySQL. My goal is to implement a like/dislike system for comments. After doing some research, I found that many suggest disabling the like button after a single click. However, I want users to be able to se ...

Encountered an exception while trying to retrieve data with a successful status code of 200

Why is a very simple get() function entering the catch block even when the status code is 200? const { promisify } = require('util'); const { get, post, patch, del } = require('https'); //const [ getPm, postPm, patchPm, deletePm ] = [ ...

Notify of a specific value in an array that is retrieved through an AJAX request

I'm currently facing an issue with trying to display the value obtained from an ajax call. The code snippet below is functional in such a way that it will successfully alert the value of 'row' when grid.onClick is triggered. However, I am st ...

The horizontal display of JqueryMobile radiobuttons is not appearing correctly

My aim is to dynamically generate a set of radio buttons using JQueryMobile. Everything seems to be working fine except for the data-type='horizontal' attribute: On looking at this fiddle, you'll notice that the "created-via-js" radio group ...

The variable referencing an unidentified function has not been defined

I've created an anonymous function assigned to a variable in order to reduce the use of global variables. This function contains nested functions for preloading and resizing images, as well as navigation (next and previous). However, when I try to run ...

Set up dynamic restrictions for the length of an HTML paragraph with PHP

I am attempting to dynamically set the limit of content retrieved from a database in PHP. Specifically, I need to trim the input from the database before assigning it to an HTML paragraph. I attempted to use the substr function but was unsuccessful. Can y ...