Unusual phenomenon of child unordered list interacting with parent list item's animation

http://jsfiddle.net/RedKnight91/Z6Ueu/4/

Hey there! Take a look at the last menu (at the bottom). When you hover over one of the LIs with the "+" symbol that have children UL, which is a submenu, the slideToggle displays the child UL, but after the animation finishes, it changes width.

This issue seems more prominent in Chrome.

Any ideas on what might be causing this problem?

Here is the code snippet:

HTML

<ul class="vertical extend color">
        <li class="father">Uova
            <ul>
                <li>Fresche</li>
                <li>Di terra</li>
                <li>Artificiali</li>
            </ul>
        </li>
        <li>burro</li>
        <li class="father">zuppa
            <ul>
                <li>di legumi</li>
                <li>di ceci</li>
                <li>di fagioli</li>
                <li>fredda</li>
                <li>calda</li>
            </ul>
        </li>
        <li>limone</li>
        <li>Acqua</li>
    </ul>

CSS

ul{ padding:0; margin: 0; list-style-type: none; font-family: sans-serif; font-weight:bold; }

        li{ background: #EEE; box-shadow: 0 1px 10px #777; padding:5px; margin:0; width:150px; cursor: pointer; text-align: center; text-shadow: 1px 2px 0 white; position: relative; }
        li:hover{ background-color:#333; color:white; text-shadow: 1px 2px 0 black; }

        ul.horizontal{ display: inline; }
        ul.horizontal li { display:inline-block; zoom: 1; *display:inline; }

        ul.vertical li { margin:1px; }

        ul.extend > li:hover { background-color: #EEE; }

        li.father { padding: 5px 10px 0 0; }
        li.father ul { margin-left: -1px; display: none; padding: 0; }
        li.father:hover li { background-color:#EEE; color: #AAA; text-shadow: 1px 2px 0 white; }
        li.father:before { content: "+"; color: #555;}
        li.father:hover:before { content: "-"; color: #FFF;}​

JAVASCRIPT

$(function(){

            $("li.father").hover(
                function(){
                    $(this).find("ul").stop().slideToggle(400);
                },
                function(){
                    $(this).find("ul").stop().slideToggle(400);
                }
            );

            $("ul.extend li").not(".father").hover(
                function(){
                    $(this).animate({width:"170"}, {duration:200, queue:false});
                },
                function(){
                    $(this).animate({width: "150"}, {duration:500, easing: "easeOutBounce", queue:false});
                }
            );

            $("ul.color li").hover(
                function(){
                    $(this).animate({backgroundColor: "#333"}, {duration:100, queue:false});
                },
                function(){
                    $(this).animate({backgroundColor: "#EEE"}, {duration:100, queue:false});
                }
            );
        });​

Answer №1

this issue arises because of the specific padding settings you have applied

li.father { padding: 5px 10px 0 0; }

as a result, the nested ul inherits the same padding. To resolve this, simply remove the right padding and increase the size of li.father by 10 pixels, like this

li.father { padding: 5px 0 0 0; width: 160px; }

View the changes at http://jsfiddle.net/Z6Ueu/9/

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

Exploring date range options in Highcharts for viewing data from a specific selected date

Using HTML, JS, and Controller public function graph(Request $request) { $statistics = DiraStatistics::where('date_access',$request->date)->get(); $question_asked_sum = $statistics->sum('question_asked'); $low_ ...

Creating two separate divs that can scroll independently while also limiting each other's scroll depth can be achieved by utilizing

I am attempting to replicate the unique scrolling feature seen on this particular page. Essentially, there are two columns above the fold that can be scrolled independently, but I want their scroll depths to be linked. When a certain depth is reached whil ...

Ways to reposition JavaScript output within a webpage

I am new to HTML, CSS, and JavaScript and I have a question regarding how they work together. I can use JavaScript to display objects on the page, but I'm unsure how to move them around like other elements. Is CSS the solution for this? Any advice w ...

What strategies can be used to effectively manage multiple asynchronous requests?

I have two requirements: one is to load an image (which will take a long time on the backend server), and the other is to perform an AJAX request. I would like it to be structured like this: $.when( [perform image loading] [perform ajax request] ).t ...

Utilize JavaScript to extract and transform plain text into a JSON object through the filtering process

After receiving the plain text data from an input source, I have the following information: 1 agri dev ban lt shortform1 346 346 343 343 9,671 346 3,330,659 78 -3.00 -0.87 3.00 0.87 361.80 400.07 449.86 472.00 283.00 2 Api Pwr Cpy shortform2 355 355 347 ...

What causes the delay in a jQuery slideshow before it starts looping again?

I've been attempting to put together a basic image slideshow, however, it's not functioning as I'd like it to. My goal is to have it smoothly transition back to the first picture immediately after cycling through all the images, but there se ...

Oops! It seems like you've stumbled upon a 404 error on Django

I need to retrieve the price value immediately after a product is selected in the sale form. The sale form includes fields for price, quantity, and product. Once a user selects a product, the price of that product should populate the input box for price. T ...

Error: Unable to retrieve the name property of an undefined object within a React component that is being used as a child component within another parent component

FundraiserScreen.js // Import necessary components and dependencies; // Import Fundraiser component; const Children = ({ loading, error, fundraiserData }) => { if (loading) // Show skeleton loading HTML if (!error) return <Fundraiser fundraiser={fund ...

The event 'deviceorientation' does not seem to be firing in iOS browsers when it is referenced within an iFrame

I am currently working on a website that features a "360 panorama viewer" embedded within an iframe. The source page utilizes JavaScript and window.DeviceOrientationEvent to determine if the user is browsing on a mobile device with orientation functionalit ...

Leveraging the power of JavaScript's .map(...) method in a

Within my React code, I have a structure similar to the following: {elements.map((element) => { return ( <div> {renderDate(element.date)} </div> ) }})} This structure calls the renderDate function defined as: co ...

Why are my subpages not appearing when using nodejs?

Currently, I'm in the process of creating a basic node app for my website. So far, I have set up my app.js, controllers, and routers. However, I am encountering an issue where two out of three subpages return a 404 error, while the index page works ...

Issues arising from the combination of two variable values

I'm facing some issues trying to combine two variables and insert them into an ajax post URL. Unfortunately, I keep receiving error messages. Let me share what I have attempted so far: var photoId = 227; var jobId = 334; $.ajax({ type: "POST" ...

"Must not be currently employed" when using window.open in a basic React application

Let me share a simplified version of the webapp I'm currently developing. Whenever I run into an Uncaught Error: Should not already be working. while executing the window.open(...) line in the following code snippet: const sleep = milliseconds => ...

Create a function to produce a list of dates within two specified date ranges using JavaScript

Looking for assistance as a beginner in JavaScript. Can anyone guide me on how to generate a list of dates between dateA and dateB? For instance: dateA = 07/01/2013 dateB = 07/01/2014 Desired outcome: 07/01/2013, 07/02/2013, 07/03/2013, 07/04/2013...a ...

Forming triangles with outlines

Recently, I had the challenge of designing speech bubbles and found a clever technique to create the triangular tip at the end using CSS. By setting the element's width and height to 0 and playing around with borders, you can achieve diagonal shapes f ...

Twice the charm, as the function `$("#id").ajaxStart(...)` is triggered twice within an AJAX request

I am trying to implement the following code: <script language="javascript"> function add(idautomobile,marque,model,couleur,type,puissance,GPS){ $("#notification").ajaxStart(function(){ $(this).empty().append("<center><br/><i ...

Implementing a feature that ensures html elements are transparent in a PDF conversion

I am in the process of converting a webpage into a format that is easily printable as a PDF, while ensuring that it maintains the same appearance. Many tools for printing to PDF do not support background images or colors, so I am attempting to overcome thi ...

Tips on deactivating a button after it has been clicked once within a 24-hour period and reactivating it the following day with the use of JavaScript and Angular

Is it possible to disable my button after one click per day, and then automatically re-enable it the next day once a user has entered details using the submit button? I need assistance with JavaScript or AngularJS for this functionality. ...

Adjust the height for just one md-tab

Looking to find a way to set the height of the content within an <md-tab> element to be 100% in a flexible manner. For example, consider the following structure: <body> <md-content> <md-tabs> <md-tab label= ...

Is it possible to have animations play in reverse once they have completed running?

Hi there! I'm currently tinkering with the transitioning animations for my navigation button. I've successfully implemented the opening animation where the three bars morph into a single line and the menu slides out. Now, I'm looking to crea ...