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

Is there a way to prevent an external script from making changes to an inline style?

There is a mysterious script running on a page that seems to be controlling the height of an inline style. The source of this script modifying the height property is unknown. <div class="vgca-iframe-wrapper wpfa-initialized" style="heigh ...

Add content or HTML to a page without changing the structure of the document

UPDATE #2 I found the solution to my question through Google Support, feel free to read my answer below. UPDATE #1 This question leans more towards SEO rather than technical aspects. I will search for an answer elsewhere and share it here once I have th ...

Determining the number of columns and rows within an HTML table

Is there a way to determine the number of columns and rows in an HTML file? How can we accurately count the total number of td tags present within the HTML file? ...

How can I apply a class to the pre and code elements in Redactor?

I've been struggling for days to figure out how to add a class to the formatting option element within Redactor. By default, the "Code" formatting option wraps content in either <pre></pre> or <code></code> HTML elements. Howe ...

Having trouble selecting content in an HTML document using Xpath and response.css with Scrapy?

Something is quite puzzling me and I've been pondering over it for almost a week now. Perhaps the solution is staring right at me and I just can't see it clearly... Any hints for alternative approaches would be greatly appreciated. I have n ...

Transforming the text to be "unreadable"

I find myself in a rather odd predicament where I must display my name and contact details on a webpage. Although I am comfortable with sharing this information, I would prefer that it remain unreadable to robots or other unauthorized sources. Essentially ...

creating dynamic lists in angular.js

Could you please guide me on creating a dynamic list in Angular.js? I have successfully implemented a feature where users can add items to the list by clicking a button and filling out the required fields. To see this in action, check out this fiddle: http ...

Using JSON data with PHP, MySQL, and jQuery

I'm encountering an unusual issue. Whenever I try to access my JSON code with the corresponding numbers [0], [1], etc., I only get the first character of the object. Here's a snippet of my code: test2.php if(isset($_POST['getCustomersArr ...

What is the process for sending JavaScript with an Ajax request?

Working with ajax and javascript for the first time, I'm no expert in web development. Here is the code I've written and tested so far. I have a select div containing some options. <select id="month" onchange="refreshGraph()"> When an op ...

Trying to filter out repetitive options in an autocomplete box

Using the jQuery autocomplete plugin, I am trying to display 5 unique search results. Initially, I achieved this by limiting the stored procedure to return only 5 results, but now I want to remove duplicates while still showing 5 distinct results. I'm ...

Send PHP data through AJAX and retrieve it on a different PHP page

I need to send a variable through an AJAX URL to another PHP page and retrieve it using: $id=$_GET['id']; Here's an example where the value is passed, for instance $id=6. <a id="pageid" href="ifsc-bank.php?id=<?=$id?>"><im ...

html - Removing excess space following the footer

Having trouble getting rid of the excess white space below my footer on this website: I attempted to search for a solution online and even added padding:0; to the footer's CSS, but unfortunately it didn't solve the issue. Appreciate any assista ...

Issue with draggable div containing gmap not functioning on mobile browsers

Is it possible to make a specific div draggable without dragging the content inside, such as a gmap widget? I have tried implementing this functionality in my code and it works on a computer browser but not on a mobile browser. Here is the simplified versi ...

Video tag with centered image

For a current project, I am in need of rendering a centered image (a play button) at runtime on top of a video based on the UserAgent. If the userAgent is not Firefox, I want to display the image as Firefox has its own playEvent and button on top of the vi ...

Adjusting Font Size of Menu BarORModifying

I'm currently using WordPress to build my website. If you'd like to take a look, here is the link: I'm trying to make the font size smaller to accommodate more menu bars on the site. Any suggestions on how I can achieve this would be great ...

Angular's browser animation feature allows for smooth slide-up animations from the bottom

I have been experimenting with creating a simple animation, and it's working, but in the opposite direction of what I intended. I want the div to open from bottom to top and close from top to bottom. Here is my animation code in Angular: animations: ...

jquery logic for iterating through all elements in a select menu encountering issues

In search of a solution to iterate through all options in a dropdown list using code, comparing each to a variable. When a match is found, I aim to set that particular value as the selected item in the dropdown and then exit the loop. Here's what I&ap ...

Using jQuery to load content with a dynamic variable instead of specific element IDs

I am facing a minor jQuery issue. I am trying to load a specific area of an external HTML document into a div, but instead of loading just that particular area, the entire document is being loaded. Here's the code snippet for the trigger: $('a& ...

Tips for maintaining the active tab in Jquery even after the page is reloaded, especially for tabs that are constantly changing

$(document).ready(function(){ $('.scroll_nav li a').click(function(){ $('li a').removeClass("active_scroll"); $(this).addClass('active_scroll'); $('ul li .btn-br_all_gun').click(function(){ ...

Personalized style for text overflow property

The application is created using Angular. Within a component, we have a div containing some text: <div>abcdefghijklmnop<div> Depending on the screen size, the text should either be fully displayed or clipped. I discovered the property 'te ...