What effect does jQuery animation have on content compression?

Looking for guidance as I dive into jQuery and navigate the complexities...

HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    <script type="text/javascript" src="jquery-1.6.2.js"></script>
    <script type="text/javascript" src="script.js"></script>

</head>
<body>
    <div id="container">
        <div id="header">
        </div>
        <div id="body">
            <div id="flip_body">
                <div id="top_body">
                        <div id="top_body_left">
                        <p id="text">String test to check for wrapping</p>
                        <div id="left_test" class="test">
                        </div>
                        <div id="right_test" class="test">
                        </div>
                    </div>
                    <div id="top_body_right">
                    </div>
                </div>
                <div id="bottom_body">
                </div>
            </div>
            <div id="flip">
                <p>Flip</p>
            </div>
        </div>
        <div id="footer">
        </div>
    </div>
</body>
<html>

CSS:

#container
{
    width:1000px;
    height:600px;
    background-color:red;
}
#header
{
    width:100%;
    height:15%;
    background-color:orange;
}
#body
{
    width:100%;
    height:70%;
    background-color:yellow;
}
#top_body
{
    width:100%;
    height:100%;
    background-color:red;

}
#bottom_body
{
    width:100%;
    height:100%;
    background-color:pink;
    display:none;

}
#flip_body
{
    width:90%;
    height:100%;
    float:left;
    position:relative;
}
#flip
{
    width:10%;
    height:100%;
    float:left;
    background-color:green;
}
#top_body_left
{
    height:100%;
    float:left;
    background-color:teal;
    position:absolute;
    left:0px;
    top:0px;
    bottom: 0px;
    width: 250px;
}
#top_body_right
{   
    height:100%;
    float:left;
    background-color:black;
    position:absolute;
    left:300px;
    top:0px;
    bottom: 0px;
    width: 200px;
}
#text
{
    overflow:hidden;
}
#left_test
{
    background-color:orange;

}
#right_test
{
    background-color:red;
    width:150px;
}
.test
{
    width:100px;
    height:100px;
    float:left;
}
#footer
{
    width:100%;
    height:15%;
    background-color:blue;
}

jQuery:

$(document).ready(function(){  
    $("#flip").data("open", false);

    $("#flip").click(function() {
        // slide to the right
        if ($(this).data("open") == false) {            
            $("#top_body_left").animate({width:'toggle'},500);
            $("#top_body_right").animate({width: '+=100', duration:500});

            $(this).data("open", true);
        }
        // slide to the left
        else {
                $("#top_body_left").animate({width:'toggle'},500);
            $("#top_body_right").animate({width:'-=100'},500);

            $(this).data("open", false);
        }
    });

});

Seeking advice on how to prevent children elements within #top_body_left from rearranging or wrapping when toggling. Is there a way to toggle without impacting the layout or content structure? Considering the use of CSS clip, but unsure if it's the right solution.

Answer №1

In my opinion, it would be beneficial to wrap the content in a separate container and apply overflow:hidden to the inner container (this should be done for each block that needs to be compressed), and then compress the outer container.

Answer №2

An interesting fiddle to check out. http://jsfiddle.net/mrtsherman/4PG7w/

Elements floated to the left will fill their container from left to right. If they exceed the container width, they will wrap to a new line. Alternatively, you can place them in a container with overflow: hidden to prevent wrapping.

For a demonstration, visit this Example Fiddle - http://jsfiddle.net/mrtsherman/4PG7w/1/

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

The mobile screen size shortcuts are malfunctioning, while the regular links are functioning properly

ISSUE: Links in alias buttons are not working on mobile screen size, while normal links to other webpages like social media work fine. Description I created a project using an HTML, CSS, JS building tool from The project was exported and placed into a ...

Develop an XML document that includes CSS and DTD seamlessly incorporated

Could someone please provide me with a short code example of an XML file that includes both a DTD and CSS styles all in one file? Just need one element as an example. I'm new to XML and can't seem to find any examples with both XML and CSS comb ...

The device-width value in the viewport width setting is causing issues

My angular app desperately needs a mobile responsive design as it currently looks dreadful on mobile devices. I've tried adding <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=yes">, but ...

Unable to append Jquery attribute to a div component

My code snippet is creating a div with specific classes and elements: '<div class="ctrl-info-panel col-md-12 col-centered">'+ '<h2>You do not have any projects created at the moment.</h2>'+ '<div id="t ...

Formatting dates with JQuery

Can someone help me with validating a date field in "mm-dd-yyyy" format using the jQuery validation plugin? I want to show the message "Please enter date in mm-dd-yyyy" if the format is violated. How can I achieve this? Appreciate any assistance, thank yo ...

Tips on prefixing Bootstrap 4 classes to prevent conflicts with CSS classes

Recently, I've been focusing on creating small applications for websites. The websites hosting these apps may or may not use a css framework. To prevent any potential conflicts, I have decided to add a unique prefix to all Bootstrap classes. For insta ...

What steps can be taken to ensure the visibility and accessibility of two vertically stacked/overlapped Html input elements in HTML?

I have encountered a challenge with my HTML input elements. There are two input elements that overlap each other, and I would like to make both inputs visible while only allowing the top input to be editable. I have tried several approaches involving z-ind ...

Two hyperlinks are not visible

I've added 2 links in my header component, but for some reason, they are not displaying. It's strange because everything appears to be correct. These 2 links are part of a list within a ul element. <nav class="navbar navbar-expand-lg navbar-d ...

What is the best way to test out CSS effects before they go live

I enjoy customizing the CSS, like the posted dates on my portfolio How can I make these changes without affecting the public view of the website? One suggestion from a forum was to use .date {visibility:hidden;} ...

What is the best way to design a div that includes two separate columns for text and an image icon?

Check out this code: <?php foreach ($data as $vacancy) { ?> <div class="vacancy"> <img src="<?php echo Yii::app()->request->baseUrl; ?>/images/vacancy_icon.jpg" /> <div class="name"> < ...

Steps to remove a record from a database when a button is clicked using jQuery in CodeIgniter

I need help with deleting a record from the database when the delete button is clicked using JQuery in Codeigniter. Below is my code snippet. $("#project").on("click", ".dltbtn", function() { $("#cur_del").val($(this).attr("data-id")); }); $("#del_ye ...

Alert pops up in jQuery datepicker when an undesired selection is made

I have a NinjaForms text field with a datepicker selected for it. My goal is to display an alert to the user if they choose a date that is less than 2 weekdays from the current date. Can anyone provide me with the code needed to achieve this? ...

Improving Consistency: Achieving a Uniform a:hover Effect for Links Listed in Lists

One issue I'm having is with creating a list of links and styling them with a:hover. The problem arises when the list has a defined width wider than the links themselves, causing the LIs to change color before the As on hover. It creates a messy appea ...

Two functions that require multiple clicks to execute

My JavaScript code requires two consecutive clicks to function properly for some reason. Here is the code for the link: <a href="" onclick="select_all_com(); return false">Select All</a> Now, here is the code for the function that is called w ...

For my Bootstrap website, it's a constant struggle to balance between having a responsive menu item and ensuring its correct visual appearance

I need help with creating a unique menu design for my website. On the desktop site, I want to display "username/password/sign in" buttons, while on the mobile responsive version I only want to show a single "sign in" option that redirects users to the sign ...

Having an excessive amount of CSS Sprites or none at all can be detrimental to your website's performance

UPDATE: Attempted to adjust the height to 27px as recommended by kennypu, but still facing issues. I am working with a sprite containing multiple icons that I want to extract for navigation purposes. Unfortunately, I'm struggling to properly display ...

Tips for improving the efficiency of JSON responses for quicker request times

On my index.html page, I initiate an ajax call to fetch JSON data and upon successful retrieval, I pass the JSON to other functions. $.ajax({ type : "GET", url : 'get_data', dataType : 'json', success: function(data) { ...

Insert a section of background within the div

Does anyone know how to create a div with a partial background like the example shown here? https://i.sstatic.net/CDqCe.png I attempted to add white margin, but I'm struggling to get it right. ...

Using Ember's transitionTo method and setting a controller attribute within a callback

I am working with Ember code to transition to a specific route while also setting controllerAttr1 on 'my.route' Upon transitioning to "my.route" using this.get('router').transitionTo("my.route"), I have set up a callback function that ...

What could be the reason for my jQuery script not functioning properly on my web form that was inherited from a MasterPage?

In the head of my master page, I have included: <script src="Script/jquery.min.js"></script> <link href="Stylesheet/Master.css" rel="stylesheet" /> My webform (Login.aspx) inherits from this master page, and in Login.aspx I have: <a ...