Rotation of table columns slider

My goal is to design a table layout with 4 columns, but only display 3 columns at a time. I plan to achieve this by using a div that spans the width of the 3 visible columns and applying overflow: hidden to hide the last column. When the button is clicked, I want the third column (company 2) to slide to the left and be replaced by the fourth column (company 3), enabling a comparison between company 1 and company 3. Upon clicking the button again, I expect company 3 to slide left and company 2 to slide in from the right, returning to their original positions. This feature is essential for mobile view where all columns cannot fit on the screen.

You can view the demo here: https://jsfiddle.net/smks/U7JHM/197/

HTML

<div class="div-table">
    <div class="div-table-row header-row">
        <div class="div-table-col header-row">&nbsp;</div>
        <div class="div-table-col header-row">company 1</div>
        <div class="div-table-col header-row">company 2</div>
        <div class="div-table-col header-row">company 3</div>
    </div>
    <div class="div-table-row">
        <div class="div-table-col">Comparison 1</div>
        <div class="div-table-col">yyy</div>
        <div class="div-table-col">yyy</div>
        <div class="div-table-col">yyy</div>
    </div>
    <div class="div-table-row">
        <div class="div-table-col">Comparison 2</div>
        <div class="div-table-col">yyy</div>
        <div class="div-table-col">www</div>
        <div class="div-table-col">yyy</div>
    </div>
    <div class="divRow">
        <div class="div-table-col">Comparison 3</div>
        <div class="div-table-col">uuu</div>
        <div class="div-table-col">Mkkk</div>
        <div class="div-table-col">yyy</div>
    </div>
</div>
<br>
<button>Compare Next</button>

CSS

.div-table{
  display:table;         
  width:auto;                 
  border:1px solid  #666666;         
  border-spacing:5px;/*cellspacing:poor IE support for  this*/
  padding: 0;
  text-align: center;
}
.div-table-row{
  display:table-row;
  width:auto;
  clear:both;
  padding: 5px;
}
.div-table-col{
  float:left;/*fix for  buggy browsers*/
  display:table-column;         
  width:200px;  
  border:1px solid  #666666;
  padding: 5px;
}
.header-row {
    height: 50px;
}

Answer №1

One way to achieve this effect is by assigning classes to specific columns and then animating them accordingly. In this example, the fourth column is initially hidden with a quick animation, and then each time the button is pressed, columns three and four toggle visibility.

$(document).ready(function () {
    $(".c4").animate({
        width: 'toggle',
        opacity: 'toggle'
    }, 1); 
    $("button").click(function (event) {
        event.preventDefault();
        $(".c3, .c4").animate({
            width: 'toggle',
            opacity: 'toggle'
        });      
    });
});

You can view the updated demonstration here: https://jsfiddle.net/U7JHM/202/

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 steps should I follow to make a sticker adhere to a div?

I'm currently in the process of designing a sticker that attaches to the top of a div, much like this: https://i.sstatic.net/aG329.png <div className="upgrade-premium"> <div className="upgrade-team"> <h1>Prem ...

What are the benefits of incorporating various custom fonts through @font-face?

I feel like I must be overlooking something very simple. I have been using a single custom font with a normal font face: @font-face { font-family: CustomFont; src: url('CustomFont.ttf'); } Everything works perfectly when I use this font ...

The background image of Jquery chosen plug-ins is not visible on Firefox browser

Typically, the selected plug-in functions seamlessly across a variety of browsers, including older versions of Internet Explorer. However, I recently discovered an issue with the latest version of Firefox and the plug-in. The dropdown menu image has disa ...

Learning how to use Express.js to post and showcase comments in an HTML page with the help of Sqlite and Mustache templates

I am facing a persistent issue while trying to post new comments to the HTML in my forum app. Despite receiving various suggestions, I have been struggling to find a solution for quite some time now. Within the comments table, each comment includes attrib ...

Ways to bounce back from mistakes in Angular

As I prepare my Angular 5 application for production, one issue that has caught my attention is how poorly Angular handles zoned errors. Despite enabling 'production mode', it appears that Angular struggles to properly recover from these errors. ...

The issue of button onclick textfield validation malfunctioning

Within this container, there is a text field identified as 'codeCityId' along with a button that triggers an onclick method. When the button is clicked, the function will verify the input. function click()={ var valid = $('#codeCityId' ...

How can you effectively use asynchronous functions?

I'm currently exploring Express and asynchronous/functional programming. app.get('/users/:id', (req, res) => { let id = req.params.id; let User = require('../models/user') User.is_complete(id, (validate) => { conso ...

Toggle the availability of links based on the presence of route parameters

My routing configuration appears as follows (for readability, I've omitted the second parameter in when()): app.config(function($routeProvider, $locationProvider){ // Prepare for html5 mode $locationProvider.hashPrefix('!'); $l ...

Customizing the formatting of a listview in jQuery Mobile

Currently, I am developing a web application that utilizes the jquery mobile framework and I am interested in finding ways to enhance the customization of list view elements. Specifically, I would like to have more control over text positioning and sizing ...

Navigating in a Curved Path using Webkit Transition

Currently, I am working on a simple project to learn and then incorporate it into a larger project. I have a basic box that I want to move from one position to another using CSS webkit animations and the translate function for iOS hardware acceleration. I ...

The Bootstrap logo and the navbar are displayed on separate lines

I'm having trouble creating the navigation bar that I envision. I want the logo to be positioned on the top left, with the navigation bar centered on a new line below it. When the bar collapses, I want the button to align to the right of the logo on t ...

Trouble arises when attempting to compare two JSON files with an undefined issue

data-info.json {"price-comparison":[[{"Price":"0.0"},{"Code":"C0358102"}],[{"Price":"2.0"},{"Code":"C0876548"}]],"isEmployeeOJ":"Y"} script.js var dataInfo = $http.get("data/data-info.json").then(function (response) { $scope.dataInfo = response.data; ...

Tips for displaying a loading message during an AJAX request?

My AJAX function is set up like this: function update_session(val) { var session_id_to_change=document.getElementById('select_path').value; $.ajax({ type: "GET", url: "/modify_path/", asy ...

What is the best way to automatically log out a user once their session cookie has expired during an online exam?

While developing an MVC ExpressJS Test app, I encountered an issue with auto-logout functionality for users who stop answering test questions. The error message "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client" keeps app ...

How to keep your vue-router up-to-date

As a newcomer to vuejs, I am using vue cli 3 for my project which consists of various components. One of the components is a menu component where I retrieve all the menu items from an API (code provided below). I have integrated vue-router for routing purp ...

Utilize HTML or JavaScript to make a POST request with Express

Recently, I decided to dip my toes into the world of back-end development using express for the first time. I came across a situation where I needed to make a POST request from an html/js file, and initially used Jquery to accomplish this task. However, I ...

Adjusting the color of text inside a div when it gets cut off

I've been attempting to change the text color when it gets truncated, but so far I haven't had any luck. In the scenario presented below, the first div (numbered 1) should display in a different color. Any suggestions or recommendations would b ...

Storing the usernames of users through local storage is essential for data preservation

My instructor mentioned a unique way to store user names using "localstorage" and arrays in JavaScript. This method ensures that the names are saved even if the page is reloaded. Here is the code snippet for achieving this functionality: html: <!doctyp ...

React material ui is not compatible with custom styles that are applied to components

I've developed a unique UserIcon Component that showcases an icon along with accompanying text. Take a look at the code snippet below: import React from "react"; import PropTypes from "prop-types"; import { withStyles, Avatar, Typography } from "@mat ...

Is it possible to prioritize loading JavaScript before images on a webpage?

My goal is to prioritize loading the js first and then the images for a specific reason. I want the blue rollover effect to be applied immediately upon loading. As the number of images on this page will eventually double, this could potentially become a la ...