Seamless transition between Nuxt/Vue components as they appear and disappear on the page alongside other content

Is there a way to create a smooth transition when showing and hiding grid items on a webpage? Currently, I have a list of grid items with a button that toggles between "see more" and "see less". When the user clicks on "see more", all items are displayed, and when they click on "see less", only 3 items are shown. The transition when displaying all items is nice, but as we hide them, the elements at the bottom do not follow the motion. How can I ensure a fluid transition and prevent leaving the user in the middle of the paragraph?

Here is an example template:

<div>
  <transition-group name="list" class="grid">
      <div v-for="(content,index) in contents" :key="index" class="card">
        <h4>
          {{index}}
        </h4>
      </div>
  </transition-group>

  <button @click="onClickSeeButton">
    {{ seeButton }}
  </button>

  <p>
      Some text...
  </p>
</div>

I have used the following CSS properties for the transition:

.list-enter-active, .list-leave-active {
  transition: all 1s;
}
.list-enter, .list-leave-to {
  opacity: 0;
}

The script looks like this:

new Vue({
  el: "#app",
  data: {
    els: [1,2,3,4,5,6,7,8,9,10,11,12], // from 0 to infinite
    seeMore: true
  },
  computed: {
    contents: function(){
        return this.seeMore ? this.els.filter((el,index) => index < 3 ) : this.els
    },
    readButton: function(){
        return this.seeMore ? 'see more' : 'see less'
    }
  },
  methods: {
    onClickReadButton: function(){
        this.seeMore = !this.seeMore
    }
  }
})

Check out the code demo here.

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 passport local strategy functions properly when tested with Postman, but encounters a "missing credentials" error when used with axios

I am currently working on creating a login system using passport and a local strategy. Strangely, when I attempt to send the request through axios it doesn't seem to work, although it functions properly with Postman. When using axios, I receive an er ...

Utilizing Typescript generics in scenarios with arguments that may be either a value or a callback function

Here's the issue: I need to pass T, which could be a string, number, boolean, object, array, or a function. The problem is I can't figure out how to handle ab("hello") in this scenario and return T as a value. function a<T>(ab: T | ((v: T) ...

Omit the readme.md file from Vuepress

Currently, I am attempting to remove the README.md from Vuepress in order to utilize it for Github documentation. Instead, I have set up index.md as my homepage. Is there a method to accomplish this task successfully? I experimented with the following ap ...

I am experiencing issues with my buttons not functioning properly after implementing the fetch API in conjunction with express.js

I'm facing a peculiar issue with buttons that are meant to display templates on the client page. This code is executed on the client side. The primary function of this class is to allow the user to click a button, send a request, receive a response c ...

What is the best way to conduct a comparison between text within an HTML element and a particular value contained in an array of objects

My first attempt at creating a quiz app using JavaScript has hit a roadblock. I am facing an issue with calculating the user's score based on their selected answers and the correct ones. The userScore variable is not incrementing as expected, always s ...

Transmit variables to ajax callback function

I'm a beginner when it comes to AJAX, so I'm using 'Jquery Form' to help me out. I'm trying to pass the entry and path variables to the success callback. var optionsUpdate = { data: { entry: entry, path: path }, success: ...

Inject an HTML or jade webpage into a div within another HTML or jade webpage

I'm facing an issue in my Node.js project with a script (JS) that is responsible for loading a Jade page into a div of another Jade page using $("#div").load(directory). Despite specifying the directory of the jade page to be loaded, I keep getting an ...

What could be causing the malfunction of material-UI Tabs?

My Material UI Tabs seem to have stopped working after a recent update. I suspect it may be related to the react-tap-event-plugin update I installed. Initially, I thought it was due to tab indexing but even using values like value='a', value=&apo ...

The radio button allows for the selection of multiple items, rather than just one at a time

https://i.sstatic.net/9MEzS.png I have implemented a radio input as shown below <input type="radio" id={el.name} className="form-check-input" name={el.name} data-count={el.name} value={el.id} onChange={this.select_role.bind(this)} style={{margin: "4px ...

Utilizing DataTable in Angular 2: A Step-by-Step Guide

I am struggling to implement the DataTable in my Angular 2 application. It seems like adding a script tag directly into templates is not supported in Angular 2. Can anyone guide me on how to make this work? I have a feeling that I need to make some adjustm ...

Utilize JavaScript to redirect based on URL parameters with the presence of the "@ symbol"

I need help redirecting to a new page upon button click using a JS function. The URL needs to include an email address parameter. <form> <input type="email" id="mail" placeholder="ENTER YOUR EMAIL ADDRESS" requir ...

Unable to locate the requested document using the provided query string parameter

Searching for a specific document in my database using a query string referencing a user_id from a profile schema: ProfileSchema = Schema( user_id: type: Schema.Types.ObjectId vehicules: [VehiculeSchema] home: {type:Schema.Types.ObjectId, ref: &apos ...

JavaScript - If you change the properties of an object within an array, does it automatically set the array as needing an update?

If we were to imagine a scenario where there is an array containing 3 objects, and then I decide to access the second object by its index in order to modify one or more of its properties, what would happen? Would this modification mark the entire array a ...

Changing the way users are linked in a post using HTML tags (VUE-NODE)

I am trying to modify a body property that includes usernames @username1 and @username2. Is it feasible to use regex to transform these nicknames into router links? The desired output should be like this (with the @ removed in the link profile) <router ...

Is there a way to delete objects that are added dynamically to an array using a specific button linked to each object?

I am currently using Angular to develop a shopping list application. To facilitate testing, I have set up two pre-made lists with two and three pre-defined items each. However, the goal is for users to dynamically add both items and lists themselves in the ...

Flickering transitions in Phonegap and jQuery Mobile pages

As a beginner in Phonegap/jQuery Mobile, I have encountered a frustrating issue of a white screen appearing during page transitions. Despite trying various solutions found online, such as using -webkit-backface-visibility:hidden;, the problem persists. I ...

The JavaScript function for converting a date to a local string in the format of DD MMM YYYY is causing an error message in the browser console stating that it is not a valid function

I am encountering an issue with formatting a date string. The date is currently in the format 2021-03-31T00:00:00, and I need it to be displayed as 31 Mar 2021. In my TypeScript code, I attempted to use the following function: const formattedDate = i.Susp ...

Is it feasible to activate a Bootstrap Tooltip from a different element?

I am currently developing a system that enables users to add notes over an image they upload. Presently, I have a note div that, upon clicking, opens a text box for editing. When hovering over this div, I utilize Bootstrap Tooltip to preview the contents o ...

Utilize Javascript to create a function that organizes numbers in ascending order

Is there a way to modify this code so that the flip clock digits appear in ascending order rather than randomly? $( '.count' ).flip( Math.floor( Math.random() * 10 ) ); setInterval(function(){ $( '.count' ).flip( Math.floor( Math.rand ...

Django base .js file causing JQuery compatibility issues

In my Django base template, I am utilizing app.js within a theme. I now need to implement a modal popup using AJAX, which requires calling a jQuery function. The error below occurs when trying to call the page where the modal popup button is located, which ...