List elements vanish when list width is adjusted

I am working on a project that involves animating the width of a horizontal list to simulate a scroll closing effect.

You can view the issue in this Fiddle: http://jsfiddle.net/a5Tfu/1/

The main problem is that when the width shrinks and overlaps any element other than the first one, the content of that element disappears abruptly instead of gradually moving off the edge of the list as the width decreases.

What I aim for is to achieve the same smooth resizing effect that occurs with the first element, but apply it to all elements in the list.

Below is the CSS code:

#container {
    position: relative;
    overflow: hidden;
    width: 1000px;
    height: 400px;
}

#list {
    background: #f7f7f7;
    overflow: hidden;
    width: 1660px;
    height: 400px;
}   
    #list li {
        width: 400px;
        height: 400px;
        list-style: none;
        float: left;
    }   

        #left {
            position: relative;
            float: left;
            width: 200px;
            height: 400px;
        }

        #right {
            position: relative;
            float: right;    
            width: 200px;
            height: 400px;
        }

Here is the HTML template:

<div id="container">
    <ul id="list">
        <li>
            <div id="left">
                <p></p>
            </div>
            <div id="right">
                <p></p>
            </div>
        </li>
        <li>
            <div id="left">
                <p></p>
            </div>
            <div id="right">
                <p></p>
            </div>
        </li>
        <li>
            <div id="left">
                <p></p>
            </div>
            <div id="right">
                <p></p>
            </div>
        </li>
        <li>
            <div id="left">
                <p></p>
            </div>
            <div id="right">
                <p></p>
            </div>
        </li>
    </ul>
</div>

And here is the JavaScript code:

$(function(){

    $('#list').animate({width: '200px'}, 5000);

});

Thank you for your help!

Answer №1

Try animating the container element instead of the list using this JSFiddle example: http://jsfiddle.net/AbCdEf/

$('#container').animate({height: '200px'}, 3000);

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 best way to add border-radius to an image while incorporating padding?

I am facing an issue with images that have white padding at the top and bottom. Please refer to the attached image. Whenever I try to apply the border-radius property to these images, the edges appear distorted. Is there a way to resolve this problem wit ...

The background image is tiled repeatedly across the screen

I am facing some challenges with setting a background image in my asp.net web application. The issue is that when I set the image to no-repeat, it displays according to its resolution of 640*480 and the rest of the page remains blank. However, if I don&a ...

Using jQuery to show text upon hover using a `for` loop

I'm currently working on a webpage and incorporating a feature where hovering over specific div elements triggers the display of certain text in another div. There are 5 elements that I want to make hoverable and show text upon interaction. After imp ...

I'm wondering why using display flex with justify-content center and align-items center is not properly centering the elements both horizontally and vertically. Can anyone explain this?

As I delve into the world of JavaScript, I find myself coding simple JS, HTML, and CSS snippets to enhance my learning experience. These exercises help me grasp the concepts well enough to create various JS web elements and projects. My goal is to eventual ...

"Step-by-step guide on how to upload an image with precise dimensions

When using this code, I am attempting to upload only images that are the size of 512X512. However, I keep getting an error message saying "not a valid size of 512X512" even when selecting the correct image size. I am currently working on the code below an ...

The Angular component is failing to display the template

After following a tutorial on UI-Router () I have implemented the following states in my Angular application: angular .module('appRoutes', ["ui.router"]) .config(['$stateProvider', '$urlRouterProvider', function($sta ...

Rails question: What is the best method to link a stylesheet to a layout?

I have implemented a controller in my application that utilizes a custom layout named "special": class SessionsController < ApplicationController layout "special" ... end To complement this, I have created a new layouts/special.html.erb file: < ...

Obtain the dimensions (width and height) of a collection of images using Angular and TypeScript

Currently, I am facing an issue with my image upload functionality. My goal is to retrieve the width and height of each image before uploading them. However, I've encountered a problem where my function only provides the dimensions for the first image ...

Integrate a PHP variable into an HTML/JavaScript statement that was previously transformed from PHP

Incorporated within this PHP variable is a mix of HTML and JavaScript code. My task is to enhance it by adding another PHP variable. Specifically, I have a PHP variable denoted as $user->user_email. How can I seamlessly integrate this variable into th ...

I'm curious about the meaning of "!" in pseudo-code. I understand that it represents factorial, but I'm unsure of how to properly interpret it

Can someone explain the meaning of ! in pseudo-code to me? I understand that it represents factorial, but for some reason I am having trouble translating it. For example: I came across this code snippet: if (operation!= ’B’ OR operation != ’D’ O ...

I'm unable to provide an ID value within the modal section

<div class="table"> .... <tr *ngFor="let product of products; index as i"> <th scope="row">{{ i + 1 }}</th> <td>{{ product.name }}</td> <td>{{ product.category }}</td> <td> ...

The button now has a stylish 5px border, making it slightly larger in size. However, it seems

How can I add an active class with a 5px border-bottom on a button without increasing the button size by 5px? The box-sizing property is not working for me. Is there a simple solution to achieve this? *, *:after, *::before { -webkit-box-sizing: border ...

Personalize the bootstrap-vue styling within your Nuxt project

Currently, I am working on a nuxt project and utilizing bootstrap-vue as a styling module for my components. I am unsatisfied with the default styles provided and wish to incorporate some customization. Specifically, I aim to modify the appearance of the ...

Exploring the mechanics of an Ajax call

Feeling a little lost in the call flow of Ajax - can anyone provide some guidance? This is my HTML: <div id="myDiv"><h2>Let AJAX change this text</h2></div> <button type="button" onclick="myFunction()">Change Content</but ...

In JavaScript, navigate to a new page only after successfully transmitting data to the server

Creating a redirect page that sends data to the server before transitioning to a new page can be achieved using JavaScript as shown below. <body> <script type="text/javascript"> **** Discussion of cookie-related transactions **** document.c ...

Generate and send a form programatically using AJAX

One interesting feature on my website is the shoutbox with an edit link. When users click on this link, a prompt appears allowing them to edit their post. After submitting the edited post, a form is dynamically created and submitted to another page for pro ...

Ways to showcase HTML content in angular when receiving entities

Is there a way to properly display HTML characters using HTML entities? Take this scenario for example: Let's say we have the following string: $scope.myString = "&lt;analysis mode=&quot;baseball&quot; ftype=&quot;&quot; version ...

What is the best way to selectively create transparency for a specific color in a three.js canvas?

I'm working with a three.js canvas that I generated using liquidfun.js. However, I'm encountering an issue where the canvas is not transparent. I want to make a specific color in the canvas fully transparent, such as the whitish background. Is t ...

Tips for determining if an array has many occurrences of a string made up of separate whitespace values

Working with an Angular application that adds 'ng-star-inserted' to each node element. My task is to determine if the target element's class exists within an array. https://i.sstatic.net/v8G97k6o.png var footerElementClassList = [ &ap ...

What is the method for adjusting the border color of an ng-select component to red?

I am having an issue with the select component in my Angular HTML template. It is currently displaying in grey color, but I would like it to have a red border instead. I have tried using custom CSS, but I haven't been able to achieve the desired resul ...