Effortlessly glide through columns in Bootstrap 4

On my page, I have three columns with a class of col-md-6. Initially, only box1 and box2 are visible. When the user clicks on the button labeled BTN, I want to display box2 and box3, smoothly transitioning all boxes to the left.
I attempted using jQuery slide, but it didn't provide the desired effect.

How can I achieve a smooth left transition for the boxes?

function btnclick() {
  $("#box1").hide("slide", {
    direction: "left"
  }, 1000);
  $("#box3").show("slide", {
    direction: "left"
  }, 1000);
}
.box {
  height: 300px;
  border: black;
  border-style: dotted;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

</script>
<button onclick="btnclick()">BTN</button>
<div class="container-fluid">
  <div class="row">
    <div id="box1" class="box col-md-6">Box1</div>
    <div id="box2" class="box col-md-6">Box2</div>
    <div id="box3" class="box col-md-6" style="display:none;">Box3</div>
  </div>
</div>

Answer №1

function toggleBoxes() {

  $('#box1').animate({
    width: 'toggle'
  }, 2000);
  $('#box3').animate({
    width: 'toggle'
  }, 2000);
}
.box {
  height: 300px;
  border: black;
  border-style: dotted;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<button onclick="toggleBoxes()">Toggle Boxes</button>
<div class="container-fluid">
  <div class="row">
    <div id="box1" class="box col-md-6">Box1</div>
    <div id="box2" class="box col-md-6">Box2</div>
    <div id="box3" class="box col-md-6" style="display:none;">Box3</div>
  </div>
</div>

Answer №2

Here's a suggestion:

$("#box1").hide("slideLeft");

Alternatively

$("#box1").hide("slideUp");

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

Unusual behavior in sorting values with JavaScript

I have spent hours trying to figure this out, and the only conclusion I can come to is that when there are 14 elements to sort, it doesn't function properly, but with thirteen elements, it works perfectly. My goal is to sort DIV elements based on the ...

The input data from the MySQL database requires two page refreshes in order to be retrieved

Every time I input new values into the form fields and submit them, the page needs to be reloaded twice to display the updated values. For example, consider the $balance_2 in the 7th line. This line calculates the sum of all row values and updates the Bal ...

Functionality problem with adjusting font size in jQuery date picker

Recently, I integrated jQuery and datapicker features into my ASP .NET MVC 3 (Razor) project and noticed that the font size of the datapicker is exorbitantly large. Does anyone have any suggestions on how to adjust this issue? Your help would be greatly ...

Is there a way to modify the appearance of a text box to suit individual preferences?

Is it possible to alter the shape of a text box, creating a rectangle with a portion removed from one side? I have included an example image for reference. https://i.sstatic.net/oNyum.png I came across clip-path: polygon in CSS, but it seems to only accep ...

What is the best way to implement the concept of setting a minimum size for a scrollable element based on its content and a

In the interest of simplicity, let's assume that my fixed height is 100px. So, the CSS expression for the question in the title would be: height: min(min-content, 100px); This means to take the minimum value between content height and 100px. Unfortun ...

Tips for automatically displaying the scroll bar continuously on iOS 15 without requiring user interaction

We have a Web Application that displays a scroll bar for users to navigate through the content. The scroll bar functions correctly on desktop browsers and Android browsers, but not on Apple devices running iOS 15 (Safari Browser). Current Behavior : In ...

Utilizing Bootstrap combobox to easily select values by typing them in

I recently started utilizing the bootstrap combobox plugin on my website. Strangely, I've noticed that when selecting from the options in the dropdown list, choosing NewYork works smoothly. However, if I type "New" and attempt to select "New York" fr ...

Transform input string containing newline characters into separate paragraphs

I utilize Contentful CMS for content management and fetch the content through their API. When the content is fetched, it comes in as a JSON object. One of the keys within this object pertains to the main text block for the entry I am retrieving. This stri ...

Issues detected with Foundation Block Grid in small size setting

I created a React component to display a series of div elements on a page using the Foundation Block Grid system to control the number of divs per row. However, I am facing an issue where the number of divs does not change when switching to a small-sized s ...

Glimmering border in jQuery width transition

I am facing a challenge in developing a horizontal accordion style slider that is not dependent on fixed widths. The issues I encountered include: The 'flickering edge' on the right-hand list item during animation Depending on the max-width set ...

Automated system is responsible for flagging and disabling comments

We are facing a puzzling issue at the moment. Our comments form allows users to submit their thoughts on news articles, and each submission is immediately accepted and displayed on the same page. Within each comment, there is a link that enables users to ...

Ways to dynamically toggle visibility and hide elements by clicking outside the specified div

I have a div that, when clicked, displays a contact us form. This form toggles between being visible and hidden. How can I make it hide when clicked on another part of the document? Here is the code: function showContactForm(){ var formWidth = &apos ...

Having problems with the classList.toggle function?

My goal is to toggle a CSS class using jQuery on an SVG element every time a div element is clicked. After researching, I discovered that there can be challenges when working with SVG elements, leading me to try this solution: $("#div1").click(function() ...

What is the best way to animate specific table data within a table row using ng-animate?

Are you working with Angular's ng-repeat to display a table with multiple rows? Do you wish to add an animation effect to specific cells when a user hovers over a row in the table? In the scenario outlined below, the goal is to have only certain cell ...

What is the best way to align an inline list in the center so that it is responsive across all

Here is the CSS code provided: .wrapper{ display: inline; line-height: 2em; width: 100%; height: 100%; min-width: 1000px; min-height: 1000px; text-align: center; } ul{ list-style: none; } li{ list-style: none; } .craftb ...

Looking for assistance with converting a basic script into a Joomla 2.5 module and resolving issues with Java integration

I'm having issues with my code in Joomla 2.5. It seems like the Java function is not functioning properly within Joomla. Can someone assist me with troubleshooting this problem? mod_mw_pop_social_traffic.php <?php defined( '_JEXEC' ) or ...

Backdrop behind of Bootstrap modal located back of other page contents

I'm facing some challenges after transferring a website I developed locally to a live server. The modal windows are appearing behind other content on the live server, although they work perfectly fine on the local version. Despite my attempts to adju ...

Attempting to display a larger version of an image sourced from miniature versions fetched with the assistance of PHP and

I'm dealing with the challenge of displaying thumbnails fetched from a database. PHP is successfully interacting with and presenting my thumbnails. I'm currently faced with the issue of passing the id from the database to the imageID in my JavaSc ...

What is the best way to generate unique mousedown callbacks on the fly?

My goal is to create multiple divs, each with a unique mousedown callback function. However, I want each callback function to behave differently based on the specific div that is clicked. Below is the code I have been using to create the divs and set the ...

Exploring the wonders of Html5 Canvas with base64 encoded images

I have a base64 encoded image that looks like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCA...... Is there a way to draw this on a canvas using the encoded image provided above? Does anyone have an example of how to do this? Updated: ...