Troubleshooting: Issue with Bootstrap carousel not displaying thumbnails properly after recent modification

For the product image gallery, I have implemented this code but it seems to be having some issues. The thumbnail images are not moving the main images correctly. Can someone help me identify and solve the problem?

                        <!-- Apologies! Lightbox functionality is currently not working -->

                        <div id="myCarousel" class="carousel slide" data-ride="carousel">
                            <div class="carousel-inner">
                            @foreach (var obj in galleries.Select((item, index) => new { item, index }))
                            {
                                <div class="carousel-item @(obj.index==0?"item active":"item")" data-slide-number="@obj.item.GalleryId">
                                    <img src="/ProductFile/Gallery/@obj.item.ImageName" class="d-block w-100" alt="..." data-remote="https://source.unsplash.com/tXqVe7oO-go/" data-type="image" data-toggle="lightbox" data-gallery="example-gallery">
                                </div>
                            }
                        </div>
                    </div>

                    <!-- Carousel Navigation -->
                    <div id="carousel-thumbs" class="carousel slide" data-ride="carousel">
                        <div class="carousel-inner">
                            <div class="carousel-item active">
                                <div class="row mx-0">

                                    @foreach (var item in galleries)
                                    {
                                        <div id="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="355654475a40465059184650595056415a4718755c4150581b7254595950474c7c51">[email protected]</a>" class="thumb col-4 col-sm-2 px-1 py-2" data-target="#myCarousel" data-slide-to="@item.GalleryId">
                                            <img src="/ProductFile/Gallery/@item.ImageName" class="img-fluid" alt="...">
                                        </div>
                                    }
                                </div>
                            </div>
                        </div>
                        <a class="carousel-control-prev" href="#carousel-thumbs" role="button" data-slide="prev">
                            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            <span class="sr-only">Previous</span>
                        </a>
                        <a class="carousel-control-next" href="#carousel-thumbs" role="button" data-slide="next">
                            <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            <span class="sr-only">Next</span>
                        </a>
                    </div>

                </div>

The thumbnail of the photos isn't functioning properly as expected. Any suggestions for resolving this issue would be appreciated.

<script>
    $('#myCarousel').carousel({
        interval: false
    });
    $('#carousel-thumbs').carousel({
        interval: false
    });

    // handles the carousel thumbnails
    // https://stackoverflow.com/questions/25752187/bootstrap-carousel-with-thumbnails-multiple-carousel
    $('[id^=carousel-selector-]').click(function () {
        var id_selector = $(this).attr('id');
        var id = parseInt(id_selector.substr(id_selector.lastIndexOf('-') + 1));
        $('#myCarousel').carousel(id);
    });
    // Only display 3 items in nav on mobile.
    if ($(window).width() < 575) {
        $('#carousel-thumbs .row div:nth-child(4)').each(function () {
            var rowBoundary = $(this);
            $('<div class="row mx-0">').insertAfter(rowBoundary.parent()).append(rowBoundary.nextAll().addBack());
        });
        $('#carousel-thumbs .carousel-item .row:nth-child(even)').each(function () {
            var boundary = $(this);
            $('<div class="carousel-item">').insertAfter(boundary.parent()).append(boundary.nextAll().addBack());
        });
    }
    // Hide slide arrows if too few items.
    if ($('#carousel-thumbs .carousel-item').length < 2) {
        $('#carousel-thumbs [class^=carousel-control-]').remove();
        $('.machine-carousel-container #carousel-thumbs').css('padding', '0 5px');
    }
    // when the carousel slides, auto update
    $('#myCarousel').on('slide.bs.carousel', function (e) {
        var id = parseInt($(e.relatedTarget).attr('data-slide-number'));
        $('[id^=carousel-selector-]').removeClass('selected');
        $('[id=carousel-selector-' + id + ']').addClass('selected');
    });
    // when user swipes, go next or previous
    $('#myCarousel').swipe({
        fallbackToMouseEvents: true,
        swipeLeft: function (e) {
            $('#myCarousel').carousel('next');
        },
        swipeRight: function (e) {
            $('#myCarousel').carousel('prev');
        },
        allowPageScroll: 'vertical',
        preventDefaultEvents: false,
        threshold: 75
    });

    //$(document).on('click', '[data-toggle="lightbox"]', function(event) {
    //  event.preventDefault();
    //  $(this).ekkoLightbox();
    //});


    $('#myCarousel .carousel-item img').on('click', function (e) {
        var src = $(e.target).attr('data-remote');
        if (src) $(this).ekkoLightbox();
    });
</script>

Answer №1

Thank you for sharing the website URL. Upon reviewing your code, I have identified some issues.

To resolve the problem, you may consider implementing the following changes:

  1. I observed that the data-slide-to values start from 4 instead of 0. It should begin from 0.

<div id="carousel-selector-4" class="thumb col-4 col-sm-2 px-1 py-2" data-target="#myCarousel" data-slide-to="0">
<img src="./درنیکا گیفت _ کاسه_files/39d5e36e372942f2b2d284c0a8e1b2b8.jpg" class="img-fluid" alt="...">
</div>
<div id="carousel-selector-5" class="thumb col-4 col-sm-2 px-1 py-2 selected" data-target="#myCarousel" data-slide-to="1">
<img src="./درنیکا گیفت _ کاسه_files/3d030297d7914f67b12d775f01e562fb.jpg" class="img-fluid" alt="...">
</div>
<div id="carousel-selector-6" class="thumb col-4 col-sm-2 px-1 py-2" data-target="#myCarousel" data-slide-to="2">
<img src="./درنیکا گیفت _ کاسه_files/df7abc7f67654bce87bd5191d98f9680.jpg" class="img-fluid" alt="...">
</div>
<div id="carousel-selector-7" class="thumb col-4 col-sm-2 px-1 py-2" data-target="#myCarousel" data-slide-to="3">
<img src="./درنیکا گیفت _ کاسه_files/7a87779468ff4b958d715d6a39d08cdf.jpg" class="img-fluid" alt="...">
</div>

  1. The JavaScript code below is likely causing the issue. Please try commenting it out or removing it altogether.

$('[id^=carousel-selector-]').click(function () {
            var id_selector = $(this).attr('id');
            var id = parseInt(id_selector.substr(id_selector.lastIndexOf('-') == id_selector));
            $('#myCarousel').carousel(id);
});

Output:

https://i.sstatic.net/wkYX0.jpg

In addition, I recommend adding arrow buttons for navigating between Next and Previous actions.

<a class="carousel-control-prev" href="#myCarousel" data-slide="prev">
          <span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#myCarousel" data-slide="next">
          <span class="carousel-control-next-icon"></span>
</a>

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

What is the benefit of using $q.all() with a single promise in AngularJS?

As I delve into this codebase, one snippet keeps popping up: $q.all([promise]).then(responseFunc); However, I find this confusing. After reading the documentation, I wonder why not simply use the following, as it's just a single promise... promise. ...

Using Angular JS to connect Promises while preserving data

There have been discussions about chaining promises, but this scenario presents a unique challenge. I am currently working on making multiple http get requests in my code. The initial call returns an array, and for each object in this array, another http c ...

The new data is not being fetched before *ngFor is updating

In the process of developing a "Meeting List" feature that allows users to create new meetings and join existing ones. My technology stack includes: FrontEnd: Angular API: Firebase Cloud Functions DB: Firebase realtime DB To display the list of meeting ...

The action of clicking cannot be performed on an undefined object

I'm currently working on implementing a jQuery 'slide toggle' feature. In the header of my webpage, I have added the following script: <script src="http://code.jquery.com/jquery-latest.js"></script> Here is the code snippet for ...

What is causing my page to automatically refresh whenever I click on buttons?

The code snippet below shows the structure of my webpage : HTML : <button class="add-col"><i class="fas fa-columns"> Add a column</i></button> <div class="table-responsive"> <table class="table"> ...

Creating an inner shadow effect for geometric shapes with text inside - a step-by-step guide!

Is it possible to apply an inner shadow to geometric shapes with text inside using CSS? This is the effect I want to achieve: https://i.stack.imgur.com/XcGS2.png I followed the code provided in this thread: Required pentagon shape with right direction ...

Manage your video playback by tracking the movement of your mouse on the screen

Is it possible to use mouse position on screen to control a video? Imagine, if I have my cursor on the left side of the screen, the video starts from the first frame. But as I move my cursor to the right side, the video progresses until the cursor reaches ...

"What is the best way to create a hyperlink in Google Apps Script using HTMLService? (encountering an error with the connection to accounts.google.com

Trying to utilize the Apps Script method setContent() in Google Apps Script to insert a link into a basic index.html file. var newDocLink = "https://docs.google.com/document/d/1loBt7T7-4qd0ORBXiTFeDQxuG..."; // newDocLink variable is set with a Googl ...

Error message: The Modelviewer is unable to load the local file, displaying the message "Unauthorized to access local resource."

For my WebAR project, I am utilizing Google's ModelViewer. In my vue.js project, I have a component that loads the model using the <model-viewer> attribute. My goal is to set the src attribute of the model-viewer to the absolute path of the .gl ...

Unable to establish connection with Azure Cloud Blob Storage due to certificate authentication error

Utilizing the Azure Storage Client Library for connecting to my azure blob storage and uploading files has been smooth sailing so far. I have included a snippet of the code I'm using to establish the connection and create a blob container: var storag ...

Tips for dynamically inserting a tabbed element into a list using AngularJS

I am trying to dynamically add elements with tabs in the list, but I encounter a problem where the device info gets overridden from the last user. You can see the issue here: https://i.sstatic.net/O1uXK.jpg This is how my Tabs item looks like in HTML: & ...

In Vue.js, modifying a parent component variable using $parent does not update the interpolation syntax

Child component <template> <div> <h3>Child Component</h3> <div> <button @click="changeValue()">Update Parent Value</button> </div> </div> </template> <script> export ...

Tips for appending a new row to the ToolBarContent within a MudTable

I am currently facing a challenge in adding a second row with MudChipSet for my Filter within the ToolBarContent of MudTable. My main concern is ensuring that the first row remains unaffected by this addition. Below is my existing code, and I would appreci ...

Is there a way to retrieve the final value from an Observable?

Trying to retrieve the last value from an observable. Here is an example of the code: // RxJS v6+ import { lastValueFrom, Subject } from 'rxjs'; import { scan } from 'rxjs/operators'; async function main() { const subject = new Subje ...

The TouchableOpacity function is triggered every time I press on the Textinput

Every time I press on a text input field, the login function is called This is the touchable statement: <TouchableOpacity style={InputFieldStyle.submitButton} onPress={this.login(this.state.email, this.state.password)}> <Text ...

What is the process of securing a directory with a password using Node.js and Express?

I am in the process of creating a basic web server using Node.js and Express. My aim is to host various static files, one of which includes a Unity WebGL game. In order for the game to function properly, numerous assets need to be loaded. I am interested ...

Extract information from an external website using AJAX in Laravel

On my cart page, I utilize ajax to retrieve destination information from the user and provide them with shipping options to calculate their shipping cost. While everything is functioning properly, one issue remains: I am unsure of how to iterate through t ...

The system considers the resource as a script, yet it was transmitted with the MIME type of text

I am encountering an issue when trying to integrate AngularJS/JavaScript into my HTML document. Each time I try to load my index.html file, the following error message appears: Resource interpreted as Script but transferred with MIME type text/html: "http ...

Troubleshoot: Unable to trigger change event for input type file

Hey, I'm trying to capture and display the file name that a user selects using an input type file control. Unfortunately, the jQuery onchange event doesn't seem to be working in IE 8. Does anyone have a solution for this? // Here's my jQuer ...

Ways in which a CheckedListBox can be organized

My CheckedListBox is structured as follows: Fruits .....Banana .....Apple Countries Cars .....Maruti .....Toyota Planes Students Animals Even though the italicized items are not technically child nodes, they are grouped with their respective parent node ...