Transitioning with Vue.js by sliding up

Discovering vue transitions as a newcomer to Vue has been quite an experience. I am currently working on animating a div by moving it up and expanding its width upon clicking, but I'm still wrapping my head around the concept of transitions. Below is a visual representation of my goal along with the accompanying code.

<template>
  <div class="hello">
    <transition name="slide">
      <div class="meal__status">
        <a @click="toggle = !toggle; move();" class="meal__status-wrap"></a>
      </div>
    </transition>
    <div v-if="toggle" class="overlay"></div>
  </div>
</template>
<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      toggle: false
    };
  },
  methods: {
    move() {}
  }
};
</script>
<style scoped>
.overlay {
  background: rgba(0, 0, 0, 0.9);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: block;
  text-align: center;
  transition: opacity 500ms;
  opacity: 1;
}
.meal__status-wrap {
  background-color: #42b983;
  height: 60px;
  width: 70px;
  display: block;
  position: relative;
  z-index: 99999;
}

</style>

Here is the link to the Code Sandbox where you can view the implementation https://codesandbox.io/s/awesome-matsumoto-7rlxb?file=/src/components/HelloWorld.vue

This image represents what I have achieved so farhttps://i.sstatic.net/D1aCB.png

And this image showcases the ultimate goal that I am striving for https://i.sstatic.net/dWl5K.png

Answer №1

Utilize transitions specifically for elements that are displayed/hidden using v-if or v-show. Since neither v-if nor v-show is being used in this case, it would be unnecessary and ineffective to apply a transition.

Instead, employ a class toggle on the element with an @click event handler and then customize the styling of the element based on that class.

<template>
  <div class="hello">
    <div
      class="meal__status"
      :class="{ 'meal__status--active': mealStatusActive }"
      @click="mealStatusActive = !mealStatusActive"
    ></div>
    <div class="overlay"></div>
  </div>
</template>
<script>
export default {
  name: "HelloWorld",
  data() {
    return {
      mealStatusActive: false
    };
  }
};
</script>
<style scoped>
.meal__status {
  background-color: #42b983;
  height: 60px;
  width: 70px;
  display: block;
  position: relative;
  z-index: 99999;
}
.meal__status--active {
  margin-top: -60px;
  width: 100%;
}
.overlay {
  background: rgba(0, 0, 0, 0.9);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: block;
  text-align: center;
  transition: opacity 500ms;
  opacity: 1;
}
</style>

Answer №2

Upon reviewing your previous post, it appears that the issue in your code sample pertains to CSS. To resolve this, you will need to adjust the width of the box from 70px to 100% upon clicking on it. In order to achieve this, you can create a new CSS class:

.meal__status--active .meal__status-wrap {
  background-color: #42b983;
  height: 60px;
  width: 100%;
  display: block;
  position: relative;
  z-index: 99999;
}

Answer №3

Vue Transition is designed for smooth transitions between Vue states or routes (like page transitions). While it can also be used for on-screen animations, using plain old @keyframe animation in CSS might be just as simple for your needs.

To start using Vue Transitions, wrap the element you want to transition inside transition tags. Then, add a condition like v-if, which will render the element if the condition is met.

<transition name="myTransition">
  <div class="someClass" v-if="myCondition">Thingy to transition</div>
  <!-- you can have multiple elements in here -->
</transition>
<button v-on:click="myCondition = !myCondition">Toggle</button>

You'll also need to define CSS classes based on the transition name to specify different states of the transition. For example, using Opacity:

.someClass {
   transition: opacity 0.5s ease;
}
.someClass.myTransition-enter {
   /* example showing chained classes since the myTransition- is added */
   opacity: 0;
}
.someClass.myTransition-enter-to {
   opacity: 1;
}

Vue will automatically apply and remove these classes during different stages of the transition on elements with v-if.

While Vue Transitions handle transitioning between states, Vue can also manage an element's state without them.

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

Detect click outside in JavaScript for closing

While this topic has been discussed before, each issue presents its own unique challenges. Despite trying various solutions and examples for making the submenu close when clicking outside of it, I have not had any success. Is there a way to make the uslug ...

Conceal the div if a choice has not been made

Here's a scenario where a div appears if text is selected that is not just a space, but remains visible even after the selection is removed. Is there a way to hide the div if the selection becomes empty? $("#actual_verse").mouseup(function() { va ...

Retrieve tagged photos from the News Feed using the Graph API

I'm looking to access all photos from a user's newsfeed on Facebook through the Graph API. I want to retrieve not just the posted photos, but also those that the user has commented on, been tagged in, or where their friends have been tagged. Is t ...

Utilizing form data to dynamically create HTML content

Seeking a solution to extract data from a form similar to this one: <form id="rendered-form" name="rendered-form"> <div class="rendered-form"> <div class="fb-text form-group field-text-1534368808722"> <label class="fb-text ...

What is the best way to include several lines between code blocks using Prettier?

After implementing Prettier into my coding workflow, I encountered an issue where it lacks the ability to adjust the number of blank lines between code blocks. By default, it only includes one blank line. I am in need of 2 blank lines: const bar = 10; // ...

Are the scripts conflicting with one another and negating their effects?

Seeking assistance with creating HTML, CSS, and Jquery code for a slideshow on my website. I am relatively new to this and struggling to get it right. I want the slideshow on to match the one on . There are two issues - the button to switch images is not ...

The fetch request became unresponsive and failed to return any data

A ComboBox.js component is interacting with a PHP server. The issue arises in the componentDidMount method, where a fetch call triggers, causing the browser to stall at "http://localhost:3000/search?code=b12a2302e2d0f2b22143b7b4e0472901b2c1b9a8&state=x ...

Adjusting image width to fit the screen while maintaining its aspect ratio and maximum size

I am seeking a solution to display an image that adjusts its width to fit the browser screen, while also resizing its height according to the aspect ratio without exceeding its original size. I came across this post, and although it provided some guidance, ...

What is the best way to use a HTML link to toggle the visibility of a <p> element using

I've been trying to figure out how to make a link show and hide a paragraph below it for some time now. I want to do this using just CSS. The paragraph should be hidden by default, then display when the link is clicked, and hide again with another cl ...

Link various data to various text boxes using a common ngModel property in Angular 8

In my project, I am working on creating a time-picker that will open when the user focuses on a text-box. The challenge I'm encountering is that although there are multiple text-boxes on a single page, binding the selected value from the time-picker u ...

Ways to accomplish a task prior to form submission without relying on preventDefault

How can I perform an action before form submission without using e.preventDefault();? I am faced with a situation where I have two form buttons and need to set a hidden field value before submitting the form. In my Symfony2 framework, when I submit the fo ...

Creating Divs in a Row with Bootstrap 5

I want to display these two images next to each other Check out my code:- code <div class="container-md"> <div class="row"> <div class="col-md-4"> <p> Image Video Live Streamin ...

If there are no subcategories within a category, the category should be hidden

I need help restructuring categories and sub-categories. I want the category to be removed as well when all its subcategories are deleted. In other words, only display a category if it has existing subcategories. Any suggestions would be appreciated! Tha ...

How to position a collapsible button menu on the right side of the screen instead of the left using Bootstrap 4

As a newcomer to web development, I am still learning the ropes. Currently, I am facing an issue with my navbar as I try to create a flexbox menu that should pop up from a collapsible button on the left side of the screen. Unfortunately, all the attempts I ...

What is the best way to serve a .ttf file in node.js with the http and fs libraries?

I am running a basic node server and I have a CSS file that is trying to load a font from the server: @font-face{ font-family: 'NiagaraSolid-Reg'; src: url('http://localhost:1111/NIAGSOL.TTF'); } This is my attempt at servin ...

Nuxt: Generating content only for specific routes in static target, not all

I am looking to create HTML files for static deployment with specific directory structure requirements. The dependencies in the package.json are listed below: "dependencies": { "@nuxt/content": "^1.15.1", "@nuxt ...

Vue.js may encounter issues with rendering loops when values are changed using the v-model

<template> <div> <div class="form-group m-b-5"> <label for="row" class="control-label col-sm-4">Row</label> <div class="col-sm-8"> <input type="number" id="row" v-mo ...

Exclusive to Firefox: The left and right arrows will shift the entire page

I've encountered a strange issue with my website that only seems to be occurring in Firefox. When using the mouse scroll, I am able to move up and down as expected. However, when using the arrow keys, the entire page shifts to the right in approximate ...

Is there a more efficient method to achieve this task using JavaScript or jQuery?

Here is the code snippet I am currently using: $(document).ready(function() { //Document Ready $(".examples .example1").click(function() { $(".examples .example1 div").fadeToggle("slow"); $(".examples .example1").toggleClass('focused') ...

In IOS 9.0, flex items do not wrap to new lines and result in overflow

While it functions properly in other browsers, the issue arises in Safari. I require the flex items to occupy the entire width on screens smaller than 768px. Currently, they are taking up the full width of their container but remaining in a single line, wh ...