Avoid the browser from scrolling upwards when the Bootstrap carousel switches slides

I'm currently working on a VueJS app that has a page consisting of seven small carousels (Pink boxes - utilizing BootstrapVue). Each carousel showcases different products with one product displayed per slide.

Beneath the carousels are green boxes representing various unique combinations that can be created. When a user clicks on a combination, it updates each carousel to display the correct product/slide. However, there's an issue where if the page is scrolled down and a green box is clicked, the browser automatically scrolls back up to focus on the carousel that changed, especially noticeable in Firefox.

Question: How can I prevent this automatic scrolling behavior when clicking on one of the combinations? (I want the browser to stay in its current position)

https://i.sstatic.net/QWM15.png

This is how the template for my carousel is structured:

<template>
  <div class="b-capsule-layer">

    <b-carousel id="carousel1"
      ref="layerCarousel"
      :controls="showControls"
      :interval="0"
      v-model="slide"
      @sliding-start="onSlideStart"
      @sliding-end="onSlideEnd"
      @mouseenter.native="toggleHover"
      @mouseleave.native="toggleHover"
    >

      <b-carousel-slide
        v-for="(product, index) in sortedBySequence(layer)"
        class="p-3"
        :key="product.id"
        :img-src="product.image_urls[0]"
        :data-product-id="product.id"
        :data-product-index="index"
        v-on:click.native="clickProductSlide($event, product)"
      >
        <div class="brand">{{product.brand_name}}</div>
        <div class="price">{{ formattedPrice(product) }}</div>
      </b-carousel-slide>

    </b-carousel>
  </div>
</template>

Within the carousel component, there is a data value called selectedProductId, which corresponds to the selected slide/product. A watcher is in place to detect changes in selectedProductId and update the carousel accordingly.

The watcher function is as follows:

watch: {
  layerProducts: function(newVal, oldVal) {
    this.setSelectedProduct();
  },

  selectedProductId: function(newVal, oldVal) {
    if (newVal !== null || newVal == oldVal) {
      const el = document.querySelector(`[data-product-id='${newVal}']`);

      if (el && !el.classList.contains('active')) {
        this.slide = parseInt(el.dataset['productIndex']);
      }
    }
  }
}

The value of selectedProductId changes whenever the parent component of the carousel makes modifications to layerProducts, triggering the first watcher above.

Answer №1

It is important to always work with the most up-to-date releases of Vue and BootstrapVue.

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

The onClick functionality for the IconComponent (dropdown-arrow) in React Material UI is not functioning properly when selecting

I have encountered a problem in my code snippet. The issue arises when I attempt to open the Select component by clicking on IconComponent(dropdown-arrow). <Select IconComponent={() => ( <ExpandMore className="dropdown-arrow" /> )} ...

Generate a div element dynamically when an option is selected using AngularJS

I'm having trouble dynamically creating div elements based on the selected option value, but for some reason ng-repeat isn't working as expected. Can you help me figure out what I'm missing? Here's the HTML snippet I'm using - &l ...

Creating a customized pagination feature in Angular 8 without relying on material design components

I am looking to implement pagination in my Angular 8 project without relying on any material library. The data I receive includes an array with 10 data rows, as well as the first page link, last page link, and total number of pages. Server Response: { ...

Having trouble with accessing input field in a modal that was generated by TinyMCE React within a Next.JS environment

In my current project, I am utilizing Next.JS and looking to incorporate the TinyMCE editor onto my webpage. Here is the code snippet I have implemented: <TinyMceEditor selector='textarea' initialValue={ props.value } apiKey=<AP ...

The useParams() function is returning undefined, even though the parameter does exist in the destination URL

I have a complete inventory of items called "Commandes" (PS: the app is in French), displayed in a table with a column for each row that should redirect me to another component showing more details about the selected row. To achieve this, I need to utilize ...

How to retrieve a single user using server-side props in Next.js

I'm currently building a dashboard using nextjs and implementing authentication with next-auth. However, I've encountered an issue when trying to display individual user data upon login to the dashboard. It seems that I am unable to retrieve the ...

How can I design an SVG page similar to Coin360 and Market Maps?

I need to design a homepage similar to coin360.com, where I can display market maps and cryptocurrency rates. This page will be created using SVG elements for the answers section. Is there a pre-made template available for this design, or can someone gui ...

Node/Express: Defining route identifiers for the root route '/'

I am in the process of creating a directory application where content is dynamically rendered on the server based on specific parameters. This directory functions as a subapplication within a larger app running on Apache. To redirect to Node when necessary ...

Combining relationships from various models in Laravel to streamline queries

Is it possible to combine two relationships into a single query from two separate models? class User extends Authenticatable { public function relazioneFollower() { return $this->belongsToMany(User::class, 'user_follower','follower ...

Make necessary changes to empty objects within a JSON array

Modify the null objects in a JSON array. I attempted to use map, but it did not update all the JSON objects. Here is an example of a JSON array: var response = { "code": null, "message": "Total 1 records found", "result": { "ordersList": [ ...

Merging the `on('click')` event with `$(this)`

Hello everyone, this is my first time posting here. I have a question regarding the possibility of achieving a specific functionality. I would like to attach click events to a series of anchor links and then use the $.get() method to reload some icons. T ...

The clearQueue function in jQuery doesn't truly empty the queue as expected

Can you help me with this issue I'm experiencing? When the delete button is clicked, an undo button appears for 5 seconds before partially retracting, leaving about a third of the button visible at the top of the page. Hovering over the button expos ...

How can we utilize node/express/jade to serve a specific Javascript file, depending on the availability of another file?

I've recently started developing web apps and I am facing a challenge. I have configured grunt to minify/uglify JavaScript, which works fine. However, I would like the server to check if the minified JavaScript file exists, and if it does, serve it. I ...

What is the best way to utilize Vue 3's native KeepAlive component to store a child component of a webpage in memory, ensuring that it only retrieves data from its API upon initial page load?

Currently, I am working on a project using Vue 3, Vue Router 4, and script-setup. In my routes.js file, I have specified a reporting page like this: { path: '/reporting', name: 'reporting', component: () => impo ...

Switch up the background picture by chance when hovering over it with the mouse

Would you like to change the background image when hovering over an album, similar to Facebook's functionality? When hovering over an album, display a preview of 3-4 images randomly selected. How can this be achieved using jQuery? I have tried impleme ...

Updating objects within a loop while maintaining immutable state

When working on a React application, I encountered the need to update objects within a loop. The structure of my object is as follows: [{ "iD": "101", "bD": "06/02/2018", "cD": "16/04/2018" }, { "iD": "102", "bD": "06/02/2018", ...

Issue encountered when adding an item to the shopping cart using AJAX on Prestashop platform

I've come across a similar question on this platform before, but that was quite some time ago and no definitive solution was provided. So here's my query: I'm utilizing the standard Prestashop cart module and encountering an error in the con ...

Implementing v-once with v-bind:class in vue.js: A step-by-step guide

When working with Vue, I came across the following code snippet: <button v-bind:class="['mdc-tab', {'mdc-tab--active' : index===tabs.currentTab}]"></button> The issue is that this binds it to the tabs.currentTab variables, ...

Clearing a Vue.js filter: a step-by-step guide

Below is my Vue Js code where I have successfully implemented a filter to API array elements. However, I am facing an issue when trying to set up a button that clears the filter upon clicking, restoring the page to its original state without any changes. ...

What is the best way to retrieve the offsetHeight of a Component Element using Vue.js?

I am currently working on a Vue.js component and successfully inserting it into the DOM. My goal is to find out its rendered height once it's in the DOM, specifically its offsetHeight. However, I seem to be missing something obvious as I can't fi ...