&"> Define the top attribute of v-img in CSS using calculated switches-PHP Chinese Network Q&A
Define the top attribute of v-img in CSS using calculated switches
P粉704196697
P粉704196697 2023-08-30 23:50:32
0
2
412

I want to define the top attribute of v-img based on the current breakpoint of the window.

I want to define it like this:

The calculated properties are as follows:

logoTop(){ switch (this.$vuetify.breakpoint.name) { case 'xl': return "-4%" case 'lg': return "-6%" case 'md': return "-8%" case 'sm': return "-8%" case 'xs': return 0 default: return "-4%" } },

The CSS is as follows:

#logo-transparent{ z-index: 1; width: 400px; height: 300px; position: absolute; right: -1%; }

But the problem is that v-img does not have a top attribute.

I want to use computed properties to define the CSS of an image like this:

logoTop(){ return { "--top-property" : switch (this.$vuetify.breakpoint.name) { case 'xl': return 400 case 'lg': return 300 case 'md': return 300 case 'sm': return 200 case 'xs': return 0 default: return 400 } } },

Use it in CSS as follows:

top : var(--top-property) 

But it seems I can't use switch in this case.

What should I do?

P粉704196697
P粉704196697

reply all (2)
P粉300541798

Your originallogoTopcomputed property can be used instyle bindingsto set thetopposition ofv-img:

 

Demo

    P粉462328904

    switchReturns nothing. You should use a variable like this

    logoTop() { let topProperty; switch (this.$vuetify.breakpoint.name) { case 'xl': topProperty = 400; break; case 'lg': case 'md': topProperty = 300; break; case 'sm': topProperty = 200; break; case 'xs': topProperty = 0; break; default: topProperty = 400; } return { "--top-property" : topProperty } },
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!