Retrieve the centered element's object within a slideshow

I need to showcase a specific object's field on a dynamically transmitted slider, with the object always positioned in the center of the slider.

Currently, I am utilizing vue-awesome-slider and have the following code:

<v-layout>
      <v-flex xs4>
        <div >
          <p v-html="previewArtefact"></p>
        </div>
      </v-flex>
      <v-flex xs8>
        <swiper class="" :options="swiperOption" >

        <swiper-slide v-for="(artefact,i) in artefacts" :key="i" v-if="i<5">
            <web-artefact-card  :artefact='artefact'></web-artefact-card>
        </swiper-slide> 

        <div class="swiper-pagination " slot="pagination"></div>
        <div class="swiper-button-prev" slot="button-prev"></div>
        <div class="swiper-button-next" slot="button-next"></div>

        </swiper>
      </v-flex>
</v-layout>

Furthermore:

data() {
return {
  previewArtefact:
    '<i style="padding-left:10%">The text of the artefact...</i>',
  swiperOption: {
    slidesPerView: 3,
    spaceBetween: 30,
    centeredSlides: true,
    pagination: {
      el: ".swiper-pagination",
      clickable: true
    },
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev"
    }
  }
};

The slider's central slide is automatically assigned the class '.swiper-slide-active', but I am unsure how to extract the corresponding object from it. The 'previewArtefact' should contain the artefact.text.

Answer №1

That was a tough one! Here's an example that worked for me, I couldn't find any better solutions

<template>
 <div>
 <swiper :options="swiperOption" ref="mySwiperA">
  <!-- slides -->
  <swiper-slide>I'm Slide 1</swiper-slide>
  <swiper-slide>I'm Slide 2</swiper-slide>
  <swiper-slide>I'm Slide 3</swiper-slide>
  <swiper-slide>I'm Slide 4</swiper-slide>
  <swiper-slide>I'm Slide 5</swiper-slide>
  <swiper-slide>I'm Slide 6</swiper-slide>
  <swiper-slide>I'm Slide 7</swiper-slide>

 </swiper>

 <p>{{ swiper ? swiper.activeIndex : '' }}</p>
 </div>
</template>

<script>
 export default {
  data(){
   return {
    swiperOption:{
     slidesPerView: 3,
     centeredSlides: true,
     pagination: {
      el: ".swiper-pagination",
      clickable: true
     },
     navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev"
     }
    },
    swiper: null
  }
 },
 mounted(){
  this.swiper = this.$refs.mySwiperA.swiper
 }
}
</script>

If you're using Vue, make sure to set this.swiper to this.$refs.{swiper ref}.swiper in the mounted hook. Then, you can easily retrieve the active index by calling this.swiper.activeIndex

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

There is a hidden delete button obscured by another element. What steps can be taken to bring that element to the forefront and make it visible?

I'm having trouble positioning a delete button in the top right corner of a collapsible box. Despite setting it to `visibility: visible`, I can't seem to get it to display at the top of the collapsible element. Any suggestions or ideas would be g ...

Spinning loader in jquery-mobile

I attempted to implement this functionality while Javascript is generating a timetable, causing a spinner loading display. I experimented with using $.mobile.pageLoading(); $.mobile.pageLoading(true); , as well as trying out the jQuery plugin availabl ...

Error encountered during installation of Webpack and webpack-dev-server

I'm currently working on setting up Webpack and Babel for utilizing React without Create React App (CRA). While trying to install webpack-dev-server, I encountered some dependency issues. PS C:\Users\Lebedev\Desktop\projects\ ...

What is a simple way to hide the menu when the user clicks anywhere on the screen?

I've encountered an issue with my code that involves the following functionalities: 1: When a user clicks a button, it toggles the drop-down menu on or off. 2: Clicking anywhere within the webslides element should close the menu if it's displayed ...

Error message in logs: "Module not found in Firebase Cloud Functions"

I am currently exploring how to Serve Dynamic Content with Cloud Functions using NextJS. Everything is functioning properly locally when I execute firebase serve. However, upon deploying my project with firebase deploy and attempting to run my function, ...

View a specific selected newsAPI article on its own dedicated page

I have been working on a news website and successfully displayed all the articles on a single page using the news API in nodeJs. Everything is functioning well, but now I want to show the clicked article on a separate page. Although I managed to route it t ...

Why isn't my ng-model value in AngularyJs properly setting the selected option?

My select element has four options. The initial value is set using ng-init, and once set, the user can only change it from that point on. While my initial functions successfully accept the value set by ng-init and are able to change it, the selected valu ...

Ways to utilize two distinct XPATH values for a single key

When dealing with Xpath for the same object in two different portals, the paths can be: //*[@id="abc"]/fieldset/div/div/div[1]/label //*[@id="xyz"]/fieldset/div[1]/fieldset/div/div/div[1]/label In order to use both values in the same key and have Seleni ...

Getting all inline styles from an HTML string using JavaScript

(JavaScript) I am working with an html email template stored as a string. Is there a way to extract all the inline styles used in the template? For instance, if I have this input: <div style="min-width:300px;max-width:600px;overflow-wrap:break-word ...

Transmit an attached image through Express

Currently, I have an Express application that utilizes Multer to upload images. However, once the image is uploaded, the file extension is not saved as a security measure. My goal is to serve these images with the correct extensions based on their mime typ ...

After an Ajax form is completed within the .done function, a separate Ajax call must be

Within the confines of an ajax done function lies a form (It's important to note that it resides inside the .done function) $.ajax({ type: "POST", url: "?select_main", data: {}, }) .done(function(data) { <div>\n\ <form id= ...

Can you provide an example of a basic JSON structure that defines a payment transaction using PayPal?

I need a JSON example that defines a simple PayPal donation, specifically including parameters for a payment date and an option to set the donation as recurring annually. This isn't covered in the official PayPal documentation. I've attempted the ...

Issue: An error occurred with response status code 13 while trying to call the waitForCondition function

Currently, I am in the process of crafting a browser test with selenium-webdriverjs. However, I am facing an issue when executing the code snippet below; it throws back an Error:Error response: 13. browser.waitForCondition('var element = document.que ...

Extract model and relationship hasMany from a plain SQL query

I'm seeking assistance in advance. Within my program, I am working with two models: Menu and Window, each with their respective associations. db.menus.hasMany(db.windows); db.windows.belongsTo(db.windows); My goal is to create a query that produces ...

What are the steps to transform a blob into an xlsx or csv file?

An interesting feature of the application is the ability to download files in various formats such as xlsx, csv, and dat. To implement this, I have utilized a library called fileSaver.js. While everything works smoothly for the dat/csv format, there seems ...

Is it possible for search engines like google to index Javascript content that is stored within divs and loaded onto the page?

My website utilizes JavaScript to dynamically add content to div elements, like so: <script> //This content is generated by PHP var contents = [ "Item 1", "Item 2" ]; //Display the first item document.getElementById( "item" ).textCo ...

Is it possible to use an input value to rotate an element?

I'm attempting to rotate a red circle with the ID of outer using Input[type=range]. I've tried selecting the circle's style, then transforming it based on the input value, but it needs to be within the parentheses of rotateZ(), which require ...

An error was encountered when attempting to reference an external JavaScript script in the document

Could someone please provide guidance on how to utilize the document method in an external .js file within Visual Studio Code? This is what I have tried so far: I have created an index.html file: <!DOCTYPE html> <html lang="en"> <head> ...

Unable to use innerHTML function on Blogger platform

I am currently working on a basic voting system. It functions perfectly when the two files are in the same location (locally). However, once I publish it on my blogger platform, the system fails to display the results. (When a user clicks to vote, it regi ...

Tips for modifying the function of an Electron application using an external JavaScript file

This is the project structure I envision. https://i.stack.imgur.com/ocRp9.jpg kareljs folder houses an Electron app, and upon running npm start within that directory, a window appears and executes the run method of karel.js when the button Run Karel is ...