What is the best way to incorporate animation and highlight a newly inserted row in a table without altering the styles of existing rows?

In my Nuxt 3 or Vue 3-based application, I am utilizing the HTML Table and incorporating a row into it through a button click.

As I add a new row, I desire to implement a form of transition/animation so that the freshly added row is displayed with an animation effect while the existing rows remain unaffected. Additionally, I want the background color of the newly added row to transition momentarily to green or another color to indicate to the user that it is a new addition. I am wondering if it is achievable using tailwind CSS or if there are alternative methods to achieve this.

Below is the code snippet from my Nuxt 3 or Vue 3 based application:

pages/test.vue:

<template>
  <div
    class="py-8 bg-white dark:bg-slate-800 shadow-lg rounded-lg border border-gray-700 p-4 text-black dark:text-white"
  >
    <div class="max-w-screen-lg mx-auto">
      <transition-group name="table-row" tag="div" class="overflow-x-auto">
        <table
          class="w-full table-auto bg-white dark:bg-slate-800 shadow-lg rounded-lg border border-gray-700 text-black dark:text-white"
          key="table"
        >
          <caption></caption>
          <thead key="thead">
            <tr class="bg-gray-200 dark:bg-gray-700">
              <th class="py-2 px-4 font-semibold text-left">ID</th>
              <th class="py-2 px-4 font-semibold text-left">Event</th>
              <th class="py-2 px-4 font-semibold text-left">Options</th>
            </tr>
          </thead>
          <tbody key="t-body">
            <tr
              v-for="row in rows"
              :key="row.ID"
              class="hover:bg-gray-100 dark:hover:bg-gray-600"
            >
              <td class="py-2 px-4">{{ row.ID }}</td>
              <td class="py-2 px-4">{{ row.Event }}</td>
              <td class="py-2 px-4">
                <button
                  class="hover:ring-slate-200 dark:hover:ring-slate-700 dark:border-slate-700 dark:bg-slate-800 dark:ring-offset-slate-900 flex h-12 w-12 items-center justify-center rounded-full border border-slate-300 ring-1 ring-transparent transition-all duration-300 hover:ring-offset-4"
                  @click="handleOptionClick(row)"
                >
                  <span class="justify-center items-center">
                    <Icon
                      icon="ic:round-view-day"
                      width="20"
                      height="20"
                    ></Icon>
                  </span>
                </button>
              </td>
            </tr>
          </tbody>
        </table>
      </transition-group>
    </div>
  </div>
  <button
    @click="addRow"
    class="mt-4 px-4 py-2 text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 rounded-md"
  >
    Add Row
  </button>
</template>

<script setup>
import { Icon } from "@iconify/vue";
import { ref, reactive } from "vue";

const rowCount = ref(3);

const table = reactive({
  sortable: true,
});

const rows = ref([
  {
    ID: "1",
    Event: "Event 1",
  },
  {
    ID: "2",
    Event: "Event 2",
  },
]);

const addRow = () => {
  const newRow = {
    ID: rowCount.value + 1,
    Event: "RowValue : " + (rowCount.value + 1),
  };
  rows.value.unshift(newRow); // Add the new row to the beginning of the array
  rowCount.value++;

  // Highlight the newly added row with a temporary green background
  newRow.highlighted = true;
  setTimeout(() => {
    newRow.highlighted = false;
  }, 1000); // Remove the highlight after 1 second
};

const handleOptionClick = (row) => {
  console.log("Option button clicked for row:", row);
};
</script>

<style>
// Custom styles can be added here
</style>

I would appreciate guidance on how to incorporate animations and a flashing effect for the newly added row without affecting the existing ones.

Answer №1

This code snippet will create a flashing effect on an entire row, lasting 1.5s and repeating 3 times. To implement this effect, simply assign the highlight class to the tr element in your HTML:

@keyframes shimmer-row {
  from { background-color: red;}
  to { background-color: pink; }
}

#your-table-id {
  tr.highlight td {
    animation: shimmer-row 1.5s 3;
  }
}

For a working example, check out this demo: https://jsfiddle.net/n8y2g9c1/

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

Is there a way I can adjust the dimensions of this gallery?

Here is an example of what I am trying to achieve: http://codepen.io/moransh4/pen/aZOeNO How do I adjust the size of the images to be: width: 370px; height: 200px; Additionally, I want to display only 3 images per view? Ultimately, I would like the lay ...

Ensure the footer remains at the bottom of the page without utilizing a minimum height of 100

When trying to address the common issue of making the footer stay at the bottom of a page, one popular solution is to enclose everything in a div with position:relative and min-height:100%, as explained in this helpful tutorial here. The challenge arises ...

Tips for aligning a dropdown button with the other elements in your navbar

I followed the code outline from a tutorial on We3schools, but I'm having an issue with the button not aligning correctly with the navbar. https://i.sstatic.net/fSRIT.png I attempted to adjust the code for proper alignment before publishing, but was ...

Tips for creating a div that slides from the right side to the left side

I received a code from someone and I need help with making the sliding div slide from right to left. Essentially, I want the div to hide on the right side and slowly move to the left within a width of 300px. Here is the HTML code: <a id="loginPanel"&g ...

Personalized HTML selection list

When a select option is too long, it stretches the container to accommodate its length. I have created a truncate function to limit the display to 20 characters and add ellipses to prevent this stretching. I have been searching for a way to show the entir ...

Show SVG in img tag on entire screen

I am facing an issue where my SVG image is not fully visible when displayed within an img tag on the browser's full screen. The bottom part of the image gets truncated, making it inaccessible to users. Below is the code snippet I have been using: ht ...

Unable to transmit an associative array to VueJS

Here is an example of an array structure. $collection = ['x' => 3, 'y' => 4]; I am trying to pass this information to Vue but encountering some difficulties. <my-component :collection="'{!! json_encode($collection) !!}& ...

Display flash messages consistently in a designated area on the webpage instead of appearing at the top of the page in Flask

{% with messages = get_flashed_messages(with_categories=true) %} {% if messages %} {% for category, message in messages %} <div class="alert alert-{{ category }}" style=" ...

Link functioning properly for one item but failing for another

I am facing an issue with my index.html file that contains the following code: <li> <a href="imprint.html#imprint-link"> <div class="main-menu-title">IMPRINT</div> </a> </li> Clicking on the "IMPRINT" link loa ...

The Infinite scroll feature in Fuel UX is ineffective when a specific height is not defined for the

In my current project, I am utilizing Bootstrap and Fuel UX v3.4.0 with the goal of implementing Infinite scroll throughout my entire page. Unfortunately, I have encountered difficulties in achieving this implementation. By replicating the infinite scroll ...

Steps for incorporating scrollIntoView in a horizontal testimonial table

I am sorry if the title has caused any confusion, but it is exactly as it states. I want to create a testimonial card using a table as the base. I have almost completed it, but I am struggling with the final touches. For instance, I want to implement a fun ...

Guide on positioning components to the right side of the NavigationDrawer in Vuetify with VueRouter

Working on my VueJS project, I've implemented a system to display content based on the user login using Firebase and Vuex state management. When a user is logged in, the content is shown using the v-if directive. Currently, I have successfully placed ...

Invoke the mounted lifecycle once more

At the moment, my table is set up to use the v-for directive to populate the data: <table v-for="(data, idx) in dataset" :key="idx"> </table> Following that, I have two buttons that perform actions in the database, and I wa ...

Place an image at the center with a height set to 100% within a div that has a fixed height and

Apologies for asking about this topic again, but I have been unable to find a solution where the image fills 100% of the height. If you'd like to see the issue in action, here's a link to the jsfiddle: http://jsfiddle.net/BBQvd/3/ I'm just ...

`Erase content from a field once text is typed into a different field`

I have a Currency Converter with two input fields and a button. I enter the amount to be converted in the first field, and the result of the conversion appears in the second field. My question is: How can I automatically clear the second field when I type ...

Dynamic gallery with customizable features (HTML/CSS)

Seeking guidance on creating a seamless html/css gallery without any spacing between each gallery element. All elements are identical in size, housed as list items within a ul inside a div. Media queries have been established to adjust site and image siz ...

I'm having issues with my Vue CDN code, as the output is displaying {{ name }} instead of the

I'm struggling with the Vue part of my code in both my brackets and Atom editors. I've tried multiple links, including the unpkg link, but nothing seems to work. Here is the code I've been working with: index.html: <!DOCTYPE html> ...

Tips for implementing multiple nested routes using Vue.js?

Can Nested Routes be created with more than 2 levels? I am looking to implement a structure like this: +--------------------+ | User | | +----------------+ | | | Profile | | | | +------------+ | | | | | About | | | | | | +------ ...

Can Vuejs be used effectively with cshtml and js files without using webpack?

What are your thoughts on using a single .js file for all the logic when working with Vue.js and a cshtml file, similar to how Angular 1.0 operates? I find myself in a situation where I need to combine a .NET Core action controller with Vue.js. While this ...

Duplication of CSRF Tokens within Vue Router on Laravel 5.3 with Vue 2 JavaScript

I am facing an issue with the session token generation. When I send the token via AJAX or AXIOS (since I am using Vue and Vue Router for API fetching), it results in a mismatch. The response I receive when posting data shows that the AJAX token does not ...