An interactive drop-down menu with clickable options

My website has a top navigation menu that is clickable. You can find the code snippet below:

jsFiddle

The code for the navigation menu is as follows:

$("nav td a").click(function(e) {
  if ($(this).parent().hasClass('selected')) {
    $("nav .selected div div").slideUp(200);
    $("nav .selected").removeClass("selected");
    //alert("HERE!");
  } else {
    $("nav .selected div div").slideUp(200);
    $("nav .selected").removeClass("selected");
    //alert("NO HERE");
    if ($(this).next(".subs").length) {
      $(this).parent().addClass("selected");
      $(this).next(".subs").children().slideDown(200);
    }
  }
  e.stopPropagation();
});

$("body").click(function() {
  $("nav .selected div div").slideUp(200);
  $("nav .selected").removeClass("selected");
});
nav {
  background: #f0f7fa;
  color: #85a0ad;
  margin: 40px -38px 0 -38px;
  padding: 10px 38px;
}
...
...
... (CSS continues here)
...
...
</nav>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="top">
  ...
</nav>

I want to add the same navigation menu at the bottom of the page, with the menu opening upward instead of downward when clicked. I found this post, but it talks about hover-triggered menus while mine opens on click. Here are my concerns:

  1. Where do I position "position: absolute; bottom: 100%" in the CSS?
  2. How do I adjust slideUp / slideDown for upward-opening menus?
  3. How can I prevent interference between the top and bottom menus? (Initially, clicking the bottom menu closed itself due to the slideUp/slideDown actions)

Answer №1

Visit this fiddle for more information: http://jsfiddle.net/h5fjwju6/

To enhance the appearance, modify your CSS by creating a .top and .bottom class. No adjustments needed in your jQuery code!...

Changes in HTML:

<!-- Add another nav with bottom class beneath the existing top nav -->

<nav class="bottom">
   <table>
     <tr>
       ...

Alterations in CSS:

nav {
   background: #f0f7fa;
   color: #85a0ad;
   margin: 40px -38px 0 -38px;
   padding: 10px 38px;
   position:fixed;     // <-- included this
}

nav td div div {
   background-color: #f0f0f0;
   padding: 12px 0;
   display: none;
   font-size: 0.95em;
   margin: 0;
   position: absolute;
   //top: -1px;              <-- eliminated this
   z-index: 1;
   width: 190px;
}
nav.top {                 // <-- added this   
   top: 1px;              
}
nav.top td div div  {     // <-- added this
   top: 1px;             
}
nav.bottom {              // <-- added this 
   bottom: 0px;           
}  
nav.bottom td div div {   // <-- added this   
   bottom: 25px;   
}    

Answer №2

Consider incorporating the span element into the icon

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav class="top">
  <table>
    <tr>
        <td><span class="icon">&#x25BE;</span>&nbsp;<a href="#" class="clicker">Lectures</a>
        <div class="subs">......

Include this custom CSS:

td.selected span.icon{
    -ms-transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
    display:inline-block;
}

View this example

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

Using Angular 2 for Applet Integration

I am currently facing an issue with embedding my Applet .jar file into my Angular 2 Project. Many solutions suggest using the <applet></applet> tag, but I encounter the following error when attempting to do so: Unhandled Promise rejection: Te ...

Additional forward slash appears within a JSON array

I am working on a project involving nestable drag and drop functionality. When I drag and drop tiles, it generates an array in a textarea that looks like this: [{},{"id":267},{"id":266}]. However, when I post this array on the action page, it gets posted ...

Is there a way to use jQuery to load a ul from a different webpage into a div?

Progress is being made as I work on making two nearly identical pages function seamlessly together. One page features an alphabet list, and when a letter is selected, the other page filters results (last names from a PHP database query) and displays them o ...

Extracting data from an HTML table on a website

I need assistance in generating a Python dictionary mapping color names to background colors from this color palette. What is the most effective method to extract the color name strings and corresponding background color hex values? The objective is to cr ...

Encountering problems with z-indexing when positioning a child div absolutely within a parent div that is relatively positioned

<!DOCTYPE html> <html lang="pl"> <head> <title>Test z-index</title> <style> .div1 {position:relative; z-index:1; margin:10px; background:#eee; } .div2 {position:absolute; top:14px; z-index:999; ba ...

My website is being cut off

After creating this website with a viewport setup, I noticed that it is not fully visible on certain screens. When viewed on a CRT monitor at 800x600 desktop resolution or lower than 1280x800, such as on mobile devices, the content gets clipped. Is there a ...

Understanding XML parsing problems

I've decided to keep the live xml/atom-feed URL private, as it's hosted on LiveJournal. However, I'm a bit confused about how this all works: let XML_URL = "https://users.livejournal.com/<username>/data/atom"; $(function(){ ...

The request returned a 404 (Not Found) error message when trying to navigate using AngularJS

Currently, I am working on building a straightforward application using Ionic and Angular. To test my progress locally, I have set up a simple server by running Ionics ionic serve command. Below is the snippet of my playlist.html code, where I intend to s ...

Unable to remove the white space appearing below and after a div in HTML

I have been working on creating a website. You can find my JSFiddle here. On my JSFiddle, you might notice a white gap above the black image labeled INSURANCE, and another white gap below it. I've tried various solutions but haven't been able to ...

Is there a way to submit a basic HTML form using R?

As a newcomer to R programming, I am excited to apply what I am learning in the Johns Hopkins Data Science track to practical use. My current goal is to automate the process of downloading historical bond prices from the US Treasury website After explorin ...

Transforming website content into HTML code

I am in need of a solution to convert a webpage into an HTML page programmatically. I have researched several websites, but the information provided only covers converting pages into PDF formats. Currently, my program involves saving a page as .html and th ...

Align the central element in the Bootstrap menu between two other elements

My menu layout looks like this : .navbar { box-shadow: 0 5px 15px rgba(0, 0, 0, .15); background: #fff; border: 0; max-height: 73px } .navbar-center>span>a { display: inline-block; position: relative; } #header>.navbar>div:nth-child(2)> ...

What is the most effective method for transitioning between pages while incorporating eye-catching animation effects?

I'm currently working on a website and I'm looking to add some animated page transitions. Is there a method to achieve this without using ajax to call the next page and display it with all the required effects? Or should I consider using React to ...

Troubles encountered when loading pages into a div using ajax navigation

As someone new to the world of programming, I am embarking on the journey of creating a simple website for myself. Currently, my website consists of a header, navigation links, an image below the nav (to be updated later), and 3 content divs beneath that. ...

Make sure to look for the sub-division mouse-over feature

I'm struggling to phrase this question correctly. Please help me rephrase it. I am trying to detect a mouse-over event on a sub-division, but it's not functioning as expected. Here is the code I am currently using: $('#mc').hover(func ...

What are the essential Bootstrap CSS and JavaScript files that need to be connected to our HTML document?

I recently downloaded the most recent version of Bootstrap, which is version 4. Upon extraction, I noticed that it includes two folders: one for CSS and the other for JS. The CSS folder consists of approximately 12 CSS files, while the JS folder contains ...

Adjust the input value with CSS when hovering

Whenever I click on a button, the name of that button is displayed on the site. However, I am looking to change this button name when hovering over it but I am not sure how to do it. echo '<form id="button" method="POST" >&ap ...

Tips for customizing the appearance of the span tag within the option text of an HTML select

Unique Link In my current situation, I am facing an issue where the asterisk in the first option of my HTML select element should be displayed in red color. Despite my efforts to style it, the asterisk always appears in the default black color. I have pr ...

hidden behind the frame is a drop-down menu

I am currently working on a website that uses frames. The topFrame.php contains a menu with drop-down submenus, while the main frame displays the website content. However, I am encountering an issue where the submenu in the topFrame is getting hidden beh ...

Experiencing issues with retrieving information from the database

I have a form and query set up to retrieve information from a database. The issue I'm encountering is that it works perfectly when the studentcode is a number, but fails when it's a letter. I'm unsure of what might be causing this problem. A ...