Using Vue3 to conditionally display a child div based on the class of its parent div

Just starting out with Vue, I'm currently experimenting with the active classes feature from this Vue3 carousel plugin. My goal is to only show the text and link divs for the carousel__slide--active class, but at the moment, all carousel__items are displaying their respective text and links. I believe I should be able to use a v-if or v-bind to display image.text and image.link specifically for the child class carousel__slide--active, but so far, my attempts have been unsuccessful. Any guidance on this matter would be greatly appreciated.

Snippet of relevant code:

<Slide v-for="(image) in stack.images" :key="image">
  <div class="carousel__item">
    <img
      :src="image.src"
      :alt="image.alt"
      :text="image.text"
      :link="image.link"
    />
    <!-- <div class="{ 'carousel__slide--active': true }"> -->
    <!-- <div v-bind:class="{ 'carousel__slide--active': isActive }"> -->
      <div class="overlay-shown">
        <div v-if="image.text" class="stack-text">{{ image.text }}
        </div>
        <div v-if="image.link" class="stack-text">
          <a v-bind:href="image.link">View Video</a>
        </div>
      </div>
    <!-- </div> -->
  </div>
</Slide>

<style>
.carousel__slide--active > .carousel__item {
  transform: scale(1);
  box-shadow: 8px 8px 5px -4px rgba(0, 0, 0, 0.5);
  z-index: 999 !important;
}

.overlay-shown {
  width: 600px;
  height: auto;
  background-color: #006eb7;
}
</style>

Answer №1

To potentially resolve this issue, you could also consider utilizing CSS. However, if you prefer to tackle it the "vue-way," you will need to compare against the current slide to determine whether to display the content.

The documentation may not provide clear guidance on this aspect, but upon examining the source code, you'll notice that the Carousel component utilizes the modelValue to link to the current index.

Here's an example template:

<template>
  <Carousel v-model="currentSlide">
    <Slide v-for="(image, i) in stack.images" :key="image">
      <div class="carousel__item">
        <img
          :src="image.src"
          :alt="image.alt"
          :text="image.text"
          :link="image.link"
        />
        <div class="overlay-shown" v-if="currentSlide === i">
          <div v-if="image.text" class="stack-text">{{ image.text }}
          </div>
          <div v-if="image.link" class="stack-text">
            <a v-bind:href="image.link">View Video</a>
          </div>
        </div>
      </div>
    </Slide>
  </Carousel>
</template>

<script>
  // By using data or `ref` through setup
  data: () => ({
    currentSlide: 0,
  })
</script>

Therefore, you have access to the index (i in

v-for="(image, i) in stack.images"
) for comparison with currentSlide.

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

Creating an Interactive Image Gallery with PHP

I need help merging my gallery template with my PHP code to display images fetched from a database. The gallery code is provided below: <body> <section class="gallery-block cards-gallery"> <div class="container&qu ...

Steps to include a border around text and center align it:

As a beginner in Html and CSS, I am trying to create a heading with the text "Women safety" and wrap it with a border. However, when I apply the border to the text, it covers the entire width, extending both left and right. I only want the border to be a ...

Utilizing SVG elements for interactive tooltips

Can the < use > element show the rect tooltip on mouseover in modern browsers? Refer to 15.2.1 The hint element. <svg id="schematic" version="1.2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <symbol i ...

Could data be transmitted from a Vue application to another one?

On my web page, I have implemented two separate Vue apps. Due to the presence of Google ads scattered throughout the page and Vue's limitations on script tags within instances, I am unable to combine them. I am looking for a method similar to using p ...

Strategies for avoiding text wrapping in Bootstrap labels on Firefox

Within my panel and panel-body, there are multiple span elements that display dynamically. These spans behave perfectly in Safari and Chrome, wrapping to the next line when needed. However, in Firefox, they overflow strangely. Here are the comparisons: Ch ...

Having trouble populating and submitting a selected option from a dropdown menu in Angular?

Upon loading the page, the Category dropdown automatically populates with data from the database. However, when I attempt to select a value from the dropdown and click a button to post the data to a specified URL, an error occurs: ERROR Error: Error tryin ...

I implemented a proxy in my project to handle cross-domain requests, however, the requested address changes when I make a

Unable to Cross Domains http://localhost:8080/api/login has to be redirected to http://localhost:8080/index.html proxyTable: { '/api': { target: 'http://47.106.74.67:8080', changeOrigin: true, pathRewrite: ...

Achieving a layered effect: Bootstrap Navbar on Carousel

Currently, I am designing a mockup and aiming to create a full-screen carousel with the navigation bar links positioned on top of the images. At the moment, the navbar appears transparent until I scroll down the image/slider making it full screen. How can ...

The new version 5.1 of Bootstrap modal does not disable scrolling on the <body> element

I'm currently working on a project in Angular 11 using Bootstrap (v5.1.3). My main goal is to create a functionality where clicking on a card, similar to a blog post, will trigger a Bootstrap modal popup displaying the content of that specific post. B ...

Amount of information gathered through Ruby Mechanize

agent = Mechanize.new url = "---------------------------" page = agent.get(url) I am curious to find out the amount of data in kilobytes consumed by my internet service provider for fetching this information. Specifically, I would like to determine the s ...

DIV height adds a layer of design to a website, making it visually

I have a situation where one of my web pages contains a DIV element with text inside, set at 1.1em size. Here's an example: <div id="displaydiv"> <b>Hello World</b> </div> On another page, I have the same DIV element but ...

What steps can I take to ensure that this code is validated prior to proceeding to the subsequent page?

I am experiencing an issue with this HTML fieldset form code. When I click the submit button, it redirects to the next page. However, if I remove "next" from the button class, the form validates but does not proceed to the next page. Can you please help me ...

Ways to utilize the ::after pseudo class with ElementRef within Angular

Is it possible to manipulate the background-color of the ::after pseudo selector for the specified element using Angular? @ViewChild('infobubble', { read: ElementRef }) infoBubbleElement: ElementRef; ngAfterViewInit(): void { const el ...

Is there a way to shade the entire webpage background in HTML?

Instead of affecting other DOM classes, I tried using another div but it doesn't darken the whole page. This means I have to manually modify each DOM class. Is there a way to overlay the entire document with a semi-transparent gray plane? ...

Encountering a predicament when attempting to retrieve an image from an alternative

[index.jsp][5] style.css [problem][6] [folder hierarchy][7] Although everything runs smoothly when the file is located in the css directory, it fails to show any images if placed in the images folder. Kindly provide assistance. ...

The content inside the inner div does not stretch to match the height of its parent element

I want to address a specific issue I am facing with my div structure. Although it may seem similar to other questions on StackOverflow, none of the existing solutions have worked for me. The problem is that I have two child divs inside a parent div. The h ...

A guide on setting up dark mode with @nuxt/tailwind and typography

I am in the process of creating a blog with the help of nuxt.js/content and I am looking to implement dark mode using the color mode plugin. Could you provide guidance on how to enable dark mode for the articles? My attempt to use dark: prose-dark did no ...

Vue.js encountered an error: Module not found: Unable to resolve

My goal is to eventually create an open source template, but for now I am practicing with the MEVN stack without using Vue CLI and configuring webpack manually. However, I've encountered an error at this point. ERROR in ./src/app/main.js Module not f ...

When integrating express with vue-router, I am encountering an issue with the '#' symbol in my URL

The URL is displayed as localhost:3000/index#/dashboard rather than localhost:3000/index/#/dashboard It seems a bit strange. Below is my express code snippet. app.get('/index', function (req, res) { const html = fs.readFileSync(&a ...