Skip to content
Advertisement

Vue JS – How to change the position of a component that is displayed on mouse hover

I have one problem related to the location of the component. I have four pictures, when you hover over them, a certain component is displayed, it looks like this

enter image description here

If, for example, hover the mouse cursor over a yellow picture, then another component will be displayed below, and so on with all components

My problem is when the screen reaches 568 pixels, that is, the mobile version, because I need to change the position of the displayed components, because at the moment in the mobile version my components that should be displayed they look like this

enter image description here

Notice all the components are displayed at the bottom, and I need them to be displayed at the bottom of each of my images

That is, I want them to look like this.

enter image description here

You can see the given code in codesandbox

App.vue

JavaScript

EnjoyBlue

JavaScript

EnjoyGreen

JavaScript

EnjoyYellow

JavaScript

EnjoyRed

JavaScript

Advertisement

Answer

There are a million ways to do this. One simple way to accomplish what you want is to include the information in “both” places at the same time and control it’s appearance with CSS media queries. See here: https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries

So basically it would look something like this

JavaScript

Then setup some css like:

JavaScript

Now you’d just need to make sure that whenever <Cougars> is gets the mouseover event you populate the EnjoyRed component with a v-if or something and also continue to use the <component :is="..">

The CSS will control and ensure only 1 is shown at a time.

I added a barebones example of my idea on jsfiddle:

https://jsfiddle.net/y8k1pgd9/

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement