Make two divs slide to the left on the screen

Looking to animate two divs on the left side.

div1 - text content with float left
div2 - icons with float left

Upon clicking div1, it should move to the left along with the icons.

The blue boxes are moving from right to left while the "Follow us" text remains on the left side. My goal is to have the "Follow us" text on the right side and when clicked, it should move to the left just like the blue boxes.

HTML

<div id="footer">
    <div class="socialtext">Follow us</div>
    <div class="socailicons">
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
    </div>
</div>

JS

$(document).ready(function() {
   $('.socialtext').click(function () {
        $('.socailicons').toggle("slide", {
            direction: "right"
        }, 1000);
    });
});

CSS

#footer{
            width: 300px;
            border: 1px solid #FF0000;
            height: 35px;
        }
        .socialtext{
            width: 100px;
            float:left;
        }
        .socailicons{
            width: auto;
            display:none;
            float:left;
        }
        .icon{
            width: 10px;
            height: 10px;
            background: none repeat scroll 0 0 #0769AD;
            float:left;
            margin: 10px;
        }

I want the "Follow us" text to be on the right side of the box, and when clicked, it should slide to the left along with the icons. The icons are initially hidden and will only appear upon clicking the "Follow us" text.

Answer №1

A new div element has been introduced to encapsulate both the socialtext and socailicons, making it easier to manipulate them together.

Markup:

<div id="footer">
    <div id="wrapper">
    <div class="socialtext">Follow us</div>
    <div class="socailicons">
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
        <div class="icon">&nbsp;</div>
    </div>
    </div>
</div>

The CSS property float: left; has been replaced with display: inline; for enhanced dynamic behavior of the elements.

CSS Styling:

#footer {
    width: 300px;
    border: 1px solid #FF0000;
    height: 35px;
    overflow: hidden;    /* Conceals any content extending outside the border */
}
#wrapper {
    position: relative;
    right: -200px;    /* Shifts it to the right, placing .socialicons outside the border */
}
.socialtext {
    width: 100px;
    display: inline-block;
}
.socailicons {
    display: inline;
}
.icon {
    width: 10px;
    height: 10px;
    background: none repeat scroll 0 0 #0769AD;
    display: inline-block;
    margin: 10px;
}

Animate using jQuery's .animate() method instead for smoother transitions.

Javascript Functionality:

$(document).ready(function() {
    var isShown = false;
    $('.socialtext').click(function() {
        // Toggle between moving left and right
        var offset = isShown? "-=200px": "+=200px";
        isShown = !isShown;
        $('#wrapper').animate({"right": offset}, 1000);
    });
});

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

When a <dl> element is nested within an <ol>, it will be rendered as a list format

I'm facing an issue with my CSS that affects how different browsers render definition lists embedded within ordered lists. In IE10, the list displays as expected - a bulleted list inside the ordered list without affecting the numbering. However, Firef ...

Dynamic Redirects with Ajax Headers

When making an AJAX request, I expect to be redirected to a link upon success. This link should be returned in the response header as the "location" value. I have attempted to retrieve this value using xhr.getResponseHeader("location"), but it consistentl ...

Getting the value of a dynamic p tag in Angular 4: A step-by-step guide

I am currently utilizing angularjs for the development of my website. I need to retrieve the value of a dynamically generated p tag from an API. To achieve this, I have implemented jQuery in my .ts file with the code $('p.s').html();. However, I ...

Having trouble with my ReactJS application where click interactions are functioning properly on the header but not on my content

Objective: Implement an iframe displaying a YouTube video with play/pause functionality for users. Issue: Unable to interact with main content, but works correctly when placed in Navigation or Footer components. Attempted Solutions: Explored various de ...

Utilizing Bootstrap's responsive design to create optimal spacing between boxes

I have designed this webpage layout using Bootstrap. Although I have manually added margin between the rows, I now want to include vertical spacing between the columns when the page is resized. Can anyone help me achieve this? Full-size browser: Resize ...

Customizing Typefaces in JavaScript's CanvasJS

I have been working with graphs created using canvas.js. While I have successfully built the graphs, I am struggling to change the font size and font family in the output. var ctx = $("#line"); var barGraph = new Chart(ctx, { type: ...

Enable the hover font color effect to be applied to the entire li box

Is there a way to change the font color to #fff when hovering over the entire li box, instead of just the href link? Currently, the hover color switches between #fff and #666 because the full li box is not considered a link. In case it's relevant, th ...

Incorporating a dropdown change event in HTML

Is there a way to implement a Dropdown onchange function in HTML to pass value without using a submit button? I have tried it with the submit button and it works fine, but I'd prefer to use the dropdown onchange event. Can someone please assist me on ...

Step-by-Step Guide: Ensuring Only One Menu Item is Active at a Time in AngularJS

How can I make only one menu item active at a time? Currently, when I click on a specific menu item, all menu items become active. I need to remove the previous active menu item and set the currently clicked menu item as active. Can someone assist me with ...

Error message indicating that the event "OnkeyDown" is not in sync within the React application

Hey everyone! I'm a beginner in web development and I'm struggling to understand why the event "OnKeyDown" is triggered the second time. My task involves changing (increasing, decreasing) parts of a date (day, month, year, hour, minutes, seconds) ...

I am looking to utilize the findOneAndUpdate method in Node.js and MongoDB in order to update my record. However, I want to specify that

Below is the Employee schema and update function which updates all records except for the fullname field. var employeeSchema = new Schema({ fullname: { type: String, }, email: { type: String, require: true, }, mobile: { type: ...

Is it possible to convert a webpage into an image file using PHP?

Is there a way to save a webpage as an image file or capture a snapshot of a webpage using PHP, similar to how the Firefox extension Fireshot does? ...

The code executes successfully when run locally with console logging, however, it encounters issues when run

As a newcomer to the project development world, I'm navigating my way through unfamiliar territory. Currently, I'm utilizing an npm module called mal-scraper to extract data (show titles, anime links, and images) from the MyAnimeList website. My ...

Adjust Bootstrap form positioning to be fixed at the bottom of the page

Can anyone provide assistance with positioning this form at the bottom of the page? <form> <div class="form-group"> <input type="email" class="form-control" id="" aria-describedby="emailHelp" placeholder="Enter email"> &l ...

How to disable form submission using ENTER key in jQuery when alerts are present?

My form contains a text input field. To prevent the form from being submitted when ENTER key is pressed, I used this code snippet: jQuery("#inputTags").keydown(function(event) { if (event.keyCode == '13') { event.preventDefault() ...

Having difficulty extracting the specific value of a cell in a table using JavaScript

My current task involves fetching the values from a specific cell within a table using this code: function addCatAttr() { var tbl = document.getElementById("tblAttributes1"); if (tbl.rows.length > 1) { for ( var i = 1 ; i < tbl.rows.l ...

What is the best way to switch focus to the next input using jQuery?

Currently, I am implementing the autocomplete feature using jQuery and everything seems to be functioning properly. The only issue I've encountered is with Internet Explorer (IE) - when a user selects an item from the autocomplete list, the focus does ...

Introducing a new feature that allows automatic line breaks when using the detail

Looking to achieve centered text for a summary where the arrow, when clicked, reveals additional details. However, currently, the text and arrow are on separate lines. The goal is to have the arrow on the same line as the summary text and perfectly center ...

Choose the initial offspring from a shared category and assign a specific class identifier

I am trying to figure out how to apply the "active" class to the first tab-pane within each tab-content section in my HTML code. Here is an example of what I'm working with: <div class="tab-content"> <div class='tab-pane'>< ...

Customizing the primary CSS style of an element without the need to individually reset every property

Is there a way to reset just one property of a selector that has multiple properties stored in main.css, without listing all the properties and setting them to default values? I always struggle with CSS interference and constantly need to reset properties ...