Using Vue.js but unable to see Swiper's next and previous buttons?

I've been attempting to create a swiper with previous, active, and next buttons while hiding the other buttons. Unfortunately, none of my attempts have been successful. I'm currently using version 9.3.0 of the swiper package. Any suggestions on what steps I should take next?

Here is the HTML code snippet:

<div class="blog-slider__pagination swiper-pagination-clickable swiper-pagination-bullets swiper-slide-active">
    <span class="swiper-pagination-bullet swiper-button-prev" tabindex="0" role="button" aria-label="Go to slide 1"></span>
    <span class="swiper-pagination-bullet" tabindex="0" role="button" aria-label="Go to slide 2"></span>
    <span class="swiper-pagination-bullet" tabindex="0" role="button" aria-label="Go to slide 3"></span>
    <span class="swiper-pagination-bullet swiper-button-next" tabindex="0" role="button" aria-label="Go to slide 4"></span>
</div>

Below is the CSS styling:

.swiper-button-next,
.swiper-button-prev {
      width: 11px;
      height: 11px;
      display: block;
      border-radius: 10px;
      background: #062744;
      opacity: 0.2;
        transition: all .3s;
        &-active {
          opacity: 1;
          background: #747474;
          height: 30px;
          box-shadow: 0px 0px 20px rgba(109, 109, 109, 0.3);
          
          @media screen and (max-width: 768px) {
            height: 11px;
            width: 30px;
          }
        }
    }
.swiper-pagination-bullet:not(.swiper-pagination-bullet-active):not(.swiper-button-prev):not(.swiper-button-next) {
      display: none;
    }

These are the JavaScript swiper properties being used:

export default {
  name: 'Home',
    components: {
      Swiper
    },
  methods:{
  },
  mounted(){
    const swiper = new Swiper('.blog-slider', {
      spaceBetween: 30,
      effect: 'fade',
      direction: 'horizontal',
      loop: true,
      mousewheel: {
        invert: false,
      },
      // autoHeight: true,
      pagination: {
        el: '.blog-slider__pagination',
        clickable: true,
      }
    });
    
  }
}

Currently, only the active button is visible as a result of these settings.

Answer №1

In the CSS rule for .swiper-button-next and .swiper-button-prev classes, you have both display: block; and dispay: none; specified.

If you want these buttons to be visible, simply remove display: none; from the rule.

Answer №2

Here is my approach: I incorporated buttons and utilized the SlideTo function

import {Navigation,Pagination,Scrollbar, A11y,Autoplay,} from "swiper/modules";
import SwiperCore from "swiper";
SwiperCore.use([Autoplay]);
import { Swiper, SwiperSlide } from "swiper/vue";
import "swiper/css";
import "swiper/css/navigation";
import "swiper/css/pagination";
import "swiper/css/scrollbar";
import "swiper/swiper-bundle.css";
export default {
  components: { Swiper, SwiperSlide },
  data() {
    return {
      activeIndex: 0,
      pagination: {
        el: ".swiper-pagination",
        type: "bullets",
        clickable: true,
      },
    }
  },
  setup() {
    const autoplay = {
      delay: 3000, // 3 seconds delay
      disableOnInteraction: true,
    };

    return {
      autoplay,
      modules: [Navigation, Pagination, Scrollbar, A11y, Autoplay],
    };
  },
  methods: {
    onSwiperFun(swiper) {
      console.log("onswiperfun", swiper);
      this.swiper = swiper;
    },
    slideChanged(slide) {
      this.activeIndex = slide.activeIndex;
    },
    handleSlideTo(index) {
      console.log("handleSlideTo", this.swiper.slideTo);
      this.swiper.slideTo(index);
    },
  },
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.4.8/vue.global.min.js"></script>

  <div>
    <div class="swiper-wrapper">
      <swiper
        :loop="true"
        @swiper="onSwiperFun"
        ref="mySwiper"
        @slideChange="
          (val) => {
            slideChanged(val);
          }
        "
        :slides-per-view="1"
        :pagination="pagination"
        :space-between="10"
        :autoplay="autoplay"
      >
        <swiper-slide
          v-for="(item, itemind) in [1, 2, 3, 4]"
          :key="'item' + itemind"
          class="rounded-borders"
        >
          <div style="height: 200px; width: 100vh" :class="itemind%2==0?'bg-indigo':'bg-cyan'"></div>
        </swiper-slide>
      </swiper>
    </div>
    <div class="q-mt-xs">
      <div class="row justify-center q-gutter-xs">
        <div       v-for="(item, itemind) in [1, 2, 3, 4]">
          <q-btn
            round
            @click="handleSlideTo(itemind)"
            size="6px"
            :class="{ 'active-btn': activeIndex == itemind }"
            padding="10px"
            :color="activeIndex == itemind ? 'negative' : 'grey-6'"
          ></q-btn>
        </div>
      </div>
    </div>
  </div>

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

Step-by-step guide on sorting WordPress posts by a custom field date

I've created an event sidebar section that will only show the next 3 upcoming events. I have successfully set up the custom post type and custom fields, but I am struggling to figure out how to order the posts based on the start date of the events, wh ...

The alignment of the content within a div is mismatched compared to a div that doesn't have any

Can you figure out why the element with content is out of order compared to the other elements without content in the code below? This issue seems to disappear when all elements have content. Any insights on this peculiar behavior? (Thank you in advance fo ...

Image Animation Using a Rotational Control (HTML/JavaScript/...)

I am interested in achieving a specific effect with a series of images that transition from dark to light. My idea is to have a dial or slider underneath or over the frame so that when it is moved to the left, the black image is displayed, and when moved t ...

When using a Mac, Vue has trouble starting on port 80 and displays an error message

https://i.sstatic.net/mrd6D.png When starting the Vue project on macOS, the port number is set to 80. However, it appears that ports below 1024 are disabled on Mac computers. How can this issue be resolved? I'm seeking assistance in enabling the pro ...

Column 1 with fixed headers

Is there a way to make sticky headings in a single column scroll without them overlapping? Currently, my h1s are overlapping when I scroll down. Update: I would like the headings to stack on top of each other as I scroll, instead of being pushed off scree ...

utilizing a background image with a specific div identifier

I am attempting to achieve the same effect shown in this example: http://www.w3schools.com/cssref/tryit.asp?filename=trycss_background-position I want to set an image as the background of a div using an id. #wrapper { height: 900px; width: 900px; bord ...

How to position two divs next to each other using CSS with just one adjustment

Is it possible to position two divs side by side, with one of them moving continuously up and down while containing an image? I attempted the following code: <div> <div style="margin:30px;width:100px;height:250px;position:relative;float:left; ...

Vue emits events with an undefined return value

I recently came across a piece of code that allows users to download attachments. <template #link="{ item, rowdata }"> <attachment-link v-test-id="'attachment-link'" :inventory-id="item" ...

Adjustable height for text input field

Is it possible to adjust the height of a textarea dynamically based on user input, rather than relying on scrollbars when content exceeds the width and height of the field? <textarea class="form-control"></textarea> For instance, if a user ty ...

On a desktop view, the content is displayed in 4 columns, while on smaller

In my simple block, I am trying to arrange 4 items in a row on desktop and 2 items per row on smaller devices like tablets and mobile. The desired layout is shown below: https://i.sstatic.net/3i799.png To see a live demo, visit: jsfiddle Below is the HTM ...

Using Vue along with bootstrap-vue: Ensuring only one list element is expanded in a list (v-for) at any given time

In my Vue project with bootstrap-vue, I am utilizing the b-collapse feature within a v-for loop for lists. While it is functioning correctly, I am struggling to automatically close expanded list elements when a new one is clicked. Here is my question: Ho ...

What steps should I follow to create a cohesive background design using CSS?

https://i.sstatic.net/e3LYL.png Is there a way to combine two separate div elements in CSS? Currently, the image Row and col are not connected to the above SVG blob. How can I utilize the blob as a background? Based on the code provided below, they appear ...

Angular Digest Loop for Dynamic Photo Grid Styling

I have a special filter that alters the objects being filtered. However, when I apply ng-style="item.gridSize", it triggers my custom grid algorithm. This algorithm was adapted for my requirements from a source found at this link. angular.module("custom.m ...

How can I target and manipulate my browser's scrollbar with jQuery?

I need assistance with creating a sidebar that expands and collapses upon clicking from the right side of a page. I am looking to find the z-index of the scrollbar so that I can adjust it accordingly. My goal is to have the expanded sidebar nested undern ...

Divide the information in the table across several pages for easier printing

I have encountered an architectural challenge with my server-side React app. The app renders charts and tables with page breaks in between to allow a puppeteer instance to print the report for users in another application. The issue I'm facing is mak ...

Try placing the div class above the navbar in Bootstrap

I've created these fork me ribbons in CSS with the intention of placing them on top of the navbar, similar to the Github images. Here is how they currently appear: http://jsbin.com/womib/1 .ribbon { background-color: #F38419; overflow: h ...

I'm sorry, but the Vue command is not recognized

I'm encountering an issue while trying to set up Vue. I keep getting the error message -bash: vue: command not found. I followed all the installation steps as per Vue instructions, so I'm unsure why this problem is occurring. Any help would be ...

Utilizing Host Styles in Angular2 Components

In the midst of developing a custom form component for my Angular project, I am facing challenges with styling. I wish to allow variable widths for the input element and have them controlled by the host component. For instance: <my-input class="input" ...

Having trouble with i18n types not functioning correctly in Typescript and Nuxt?

I am currently utilizing NuxtJS/i18n with TypeScript and have included its types in my TS config: { "compilerOptions": { "types": [ "@nuxt/types", "@nuxtjs/i18n", ] } } However, when attempti ...

What is the best way to differentiate between words enclosed in quotation marks using colors?

Working on my shop, I've added a section for "Colors available", but now I want to color different words with different colors using Javascript, CSS, or HTML. <button onclick="getColors()">Colors Available</button> <script> ...