Enhance your website with a stylish drop-down menu from inc.com

I am trying to create a drop and hide menu effect similar to the one on

Here is my current demo: http://jsfiddle.net/elementhttp/56ThC/

    $("#1").mouseover(function(){  
    //alert("aaaaaaaaaa"); just for testing
    $(".block2").stop().fadeToggle(700);
     });
 $("#1").mouseout(function(){      
    $(".block2").stop().fadeToggle(700);
     });

$(".menu2").mouseover(function(){  
    //alert("aaaaaaaaaa"); 
    $(".con2").stop().fadeToggle(700);
     });
$(".menu2").mouseout(function(){      
    $(".con2").stop().fadeToggle(700);
     }); 

Currently, the menu 1 item fades in when hovered over but doesn't stay visible.

Thank you for helping me solve this mystery! :D

Answer №1

One issue with your submenus is that they are not direct children of the top menu, causing the 'mouseout' event to trigger whenever you move the mouse out of the menu.

To resolve this, I have fixed your HTML, Javascript, and CSS while also cleaning up some code. Here are examples of the improvements: (http://jsfiddle.net/56ThC/1/).

<body>
<div class="block">
    <div class="box" id="1">
        menu1
        <div class="submenu" id="1">
            <div class="box2">item1_1</div>
            <div class="box2">item1_2</div>
            <div class="box2">item1_3</div>
            <div class="box2">item1_4</div>
            <div class="box2">item1_5</div>
         </div> 
    </div>
    <div class="box " id="2">
        menu2
        <div class="submenu" id="2">
            <div class="box2">item2_1</div>
            <div class="box2">item2_2</div>
            <div class="box2">item2_3</div>
            <div class="box2">item2_4</div>
            <div class="box2">item2_5</div>
         </div> 
    </div>
    <div class="box" id="3">
        menu3
    </div>
    <div class="box" id="4">
        menu4
    </div>
    <div class="box" id="5">
        menu5
    </div>

 </div> 

Javascript:

$('.submenu').hide();


$(".box").hover(function(){  
    $(this).find(".submenu").stop().fadeToggle(700);
});

CSS:

.block{
    width: 615px;
    border: solid 1px #aaa;  
    text-align: center;  
    white-space: nowrap;  
    overflow: hidden;
}
.box{
    width: 100px;  
    height: 50px;  
    border: solid 1px #ccc;  
    display: inline-block;  
    vertical-align: middle;         
}   
.submenu{
    width: 615px;
    height:300px; 
    position:absolute;left:8px;top:60px;
    border: solid 1px #aaa;  
    text-align: center;  
    white-space: nowrap;  
    overflow: hidden;
            }
.box2{
    width: 200px;  
    height: 200px;  
    border: solid 1px #ccc;  
    display: inline-block;  
    vertical-align: middle;         
           }    

I hope these changes prove helpful!

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

What is the reason that my "width: auto" property is not properly adjusting to the content's width?

My css code, width: auto is causing issues with the content width I am a beginner in HTML, CSS, and JavaScript, seeking help with my website. I have multiple divs within a section element, but the section's width is not adjusting to fit the divs prop ...

CSS - Dynamic triangle separator

I've been working on creating a triangle-shaped CSS divider. Using the code snippet below, I was able to achieve the desired result: border-width: 4vw 75vw 0 23vw; However, this method feels a bit unconventional. Since you can't use percentages ...

deactivate a vessel, causing all of its contents to be rendered inactive

Hi there, I am in search of a container that has the ability to disable all elements within it, not just inputs but also images and other elements without the disabled property. I do not want to hide the container, but rather disable it. Do you know if suc ...

Utilize HTML to pre-load a font and incorporate it into your CSS styling

It is common knowledge that when we include the following code in our .css file: @font-face { font-family: "Akrobat-Regular"; src: url('/assets/Akrobat-Regular.otf') format("truetype"); } body { color: #1c1c1c ...

How can I update the color of table rows after the ng-repeat has been implemented?

My current project involves Django, Python, and a bit of AngularJS. I have a dynamic history table that grows as data is added. I am looking to apply some simple CSS to this table - specifically, I want to give every even-numbered row a black background ...

Is there a way to showcase posts with a certain tag in a single column on my tumblr theme, while reserving the other column for posts aimed at the wider audience?

I am interested in customizing my theme so that one section on the homepage of my blog only shows posts with a specific tag (such as "mine" or "personal"), while another section displays all posts, regardless of tags. Although I have searched through simi ...

Choosing just the element that was clicked and added to the DOM

I've been experimenting with JQuery in a web app I'm developing. The app involves dynamically adding elements to the DOM, but I've encountered an issue with click events for these newly added elements. I'm looking for a way to target an ...

The initial attempt to use autocomplete with Jquery UI is not functioning as expected upon entry

I'm facing a frustrating issue that's driving me crazy. I'm not an expert in javascript, but I believe the solution is simple. I'm using jQuery UI autocomplete with data retrieved from Ajax. The problem is, I only get the desired resul ...

I need to style a blockquote so that it floats to the right, but I also want it to be

I want to enhance the appearance of my blockquotes by giving them a different color background and ensuring they stand out from the regular text. Although using float:right helps achieve this effect, I prefer not to force the blockquote to the right side o ...

Second attempt at loading Jquery was unsuccessful

I have a question regarding the code snippet below that I am using to reload a PHP file after 20 seconds within a div. However, the issue I am facing is that after the initial load in my target div, it does not display anything. Do you have any suggestion ...

A Step-by-Step Guide to Setting Up a Scoreboard for Your Rock Paper Scissors Game

I'm new to JavaScript and I want to create a rock, paper, scissors game from scratch. My Game Plan: Once the user clicks on an option (rock, paper, scissors), the game will display their score and the computer's score along with the result of t ...

The jQuery code runs smoothly in the development environment, but encounters issues when published on the site

I am using jQuery to adjust the style of certain elements on my ASP.NET page, as shown below: protected void Page_Load(object sender, EventArgs e) { string scrp3 = "$(document).ready(function () {if ($('#MainContent_chbkCooperation_1& ...

Struggling to create a responsive navbar for a landing page using Next.js and TailwindCSS

I'm currently working on a landing page using nextjs, tailwind css, and shadcnui. The design looks great on desktop with a logo and two links, but it's not responsive on smartphones. https://i.stack.imgur.com/HVQsa.png On mobile devices, the lay ...

Utilizing two distinct CSS frameworks within a single Rails application

At the moment, I have an application with its frontend built using Bootstrap 3 (leveraging the bootstrap-rails gem). Now, I am looking to incorporate the Materialize.css framework into the same app. After downloading the Materialize.css stylesheet, my conc ...

What is the best way to customize column width in AG-Grid?

I am looking for a way to dynamically set column width in my table. I have provided a stackblitz example which demonstrates that when changing the screen size, only the table border adjusts, but not the column widths. Is there a way to also change the col ...

How to use AJAX to retrieve data from a JSON file hosted on an external URL?

Is it possible to extract data from a JSON file that belongs to an external source such as ABS, a company that provides weather information? The weather data is stored in a JSON File. Why am I unable to access this information and save it? & ...

How to create a Vue.js animated navbar with scroll opacity

I am looking to create a fixed navbar that changes opacity based on user scrolling behavior. Initially, I want the navbar background to be transparent and then transition to white as the user scrolls down the page. An example of what I am trying to achieve ...

The attempt to unserializing the configuration schema in Yii2 was unsuccessful

My brain feels scrambled... I am attempting to insert an image in HTML within Yii2. I retrieve it from the database and place it into the view file, but when I try to display it using HTML tags, an error is thrown. However, the image is being added perf ...

Discovering the central point within an SVG path

I am currently working with a path that is part of a group and using Jquery to locate the specific path. My goal is to find the midpoint of that path. I came across an example here. However, when attempting to use .getTotalLength(); or .getPointAtLength(), ...

"Textarea auto-resizing feature causes an excessive number of unnecessary lines to be added

I have a textarea that is coded with jQuery to limit the characters to 11 per line and automatically resize based on the number of lines. However, when users click 'Enter' to add a new line, it adds multiple extra lines instead of just one. This ...