Matching Heights for Carousel Images

My image/video carousel is causing trouble as the content within doesn't maintain a consistent height.

Clicking on the thumbnails highlights a mismatch in the main image heights. Is there a way to ensure that all elements have the same height while keeping it responsive?

(Visuals explaining the issue can be found at links - https://i.sstatic.net/lCmSG.jpg, https://i.sstatic.net/uLQCu.jpg)

For reference, here's the relevant CodePen.

Edit: The goal is to maintain consistent height for the main images displayed in the carousel, not the thumbnails.

Answer №1

The issue has been resolved by adjusting the height of all images to 70vh.

Seems like there is a glitch with StackOverflow Fiddle.

Feel free to have a look at my codepen and confirm if it meets your requirements.

$(document).ready(function() {
  // code here
});
* {
  margin: 0;
  padding: 0;
}

body {
  margin: 0;
  padding: 0;
  font-size: 100%;
}
/* CSS code here */
<script src="https://scriptsource.com/example.js"></script>
<!-- Additional Scripts -->

<body>

  <div class="slideshow-container">
    <div id="imgDetail">
      <img data-iframe="sketchfab-iframe-1" src="example.jpg" class="chair-class" data-active="true" />
      <img data-iframe="sketchfab-iframe-2" src="example2.jpg" class="chair-class" data-active="false" />
      <img src="example3.jpg" class="chair-class" data-active="false" />

      <!-- Add additional HTML elements here -->
    </div>

    <!-- Thumbnail section -->
    <div id="thumbnails">
    </div>
  </div>
</body>

Answer №2

$(document).ready(function () {
    // initiate variables
    var images = $(".chair-class");
    var thumbnailContainer = $("#thumbnails");
    var iframe1 = $('#sketchfab-iframe-1')[0];
    var iframe2 = $('#sketchfab-iframe-2')[0];
    var player1 = $f(iframe1);
    var player2 = $f(iframe2);
    
    // generate thumbnails
    generateThumbnails(images, thumbnailContainer);

    // control arrow listeners
    $(".prev-next-button").on("click", function () {
        // pause videos
        player1.api('pause');
        player2.api('pause');

        // determine next image index
        var currentImageIndex = images.index($(".chair-class[data-active=true]"));
        var isPrevious = $(this).hasClass("previous");
        var nextIndex;
        
        if (isPrevious) {
            if (currentImageIndex === 0) {
                nextIndex = images.length - 1;
            } else if (currentImageIndex > 0) {
                nextIndex = currentImageIndex - 1;
            }
        } else {
            if (currentImageIndex === images.length - 1) {
                nextIndex = 0;
            } else if (currentImageIndex < images.length - 1) {
                nextIndex = currentImageIndex + 1;
            }
        }

        // handle active classes for images
        images.removeClass("active").attr('data-active', "false");

        var $nextImage = $(images[nextIndex]);
        var iframeId = $nextImage.data('iframe');
        
        if (iframeId) {
            $(images[nextIndex]).attr('data-active', "true");
            $('.sketchfab-iframe').removeClass('active');
            $('#' + iframeId).addClass('active');
        } else {
            $(images[nextIndex]).addClass("active").attr('data-active', "true");
            $('.sketchfab-iframe').removeClass('active');
        }
    });

    // Thumbnail click event
    $(".thumb").on("click", function (event) {
        event.preventDefault();
        var images = $(".chair-class");
        var indexSelected = $(this).data("img-index");
        var currentShown = images.index($(".chair-class[data-active=true]"));

        if (currentShown === indexSelected) return false;
        player1.api('pause');
        player2.api('pause');
        images.removeClass("active").attr('data-active', "false");
        
        var iframeId = $(this).data('iframe');
        if (iframeId) {
            $(images[indexSelected]).attr('data-active', "true");
            $('.sketchfab-iframe').removeClass('active');
            $('#' + iframeId).addClass('active');
        } else {
            images.removeClass("active");
            $(images[indexSelected]).addClass('active').attr('data-active', "true");;
            $('.sketchfab-iframe').removeClass('active');
        }
    });

    // Function to generate thumbnails
    function generateThumbnails(images, container) {
        var ul = $("<ul>");
        
        images.each(function (index, element) {
            var currentThumb = $("<img>");
            var li = $("<li>");
            var src = $(this).attr("src");
            
            currentThumb.attr("src", src);
            currentThumb.attr("class", "thumb");
            currentThumb.data("img-index", index);
            
            var iframe = $(this).data('iframe');
            if (iframe) {
                currentThumb.data("iframe", iframe);
            }
            
            li.append(currentThumb);
            ul.append(li);
        });
        
        container.append(ul);
    }
});
* {
    margin: 0;
    padding: 0;
}

/* CSS styles omitted for brevity */

<!-- External libraries/scripts -->
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Daniel Pollack</title>
    <link rel="stylesheet" type="text/css" href="css/styles.css"/>
    <!-- Other scripts and links here -->
  </head>

  <body id="green-room">

    <div class="slideshow-container">
        <div id="imgDetail">
            <!-- Image details here with corresponding attributes -->

            <!-- Thumbnails section -->
            <div id="thumbnails">
            </div>


</html>

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

Is there a way to eliminate the # sign from hash data using jQuery?

Can anyone help me retrieve the hash value from the URL? var hash = window.location.hash; I am looking for a way to remove the "#" sign from the hash. Any suggestions? ...

Is it possible to extract the image name from AngularJS and then integrate it into a Laravel blade template?

I encountered a challenge when trying to integrate Laravel blade with AngularJS. Both frameworks use the same markup for displaying variables, so I modified the AngularJS variable like this: $interpolateProvider.startSymbol('<%'); $ ...

The requested resource at http://127.0.0.1:8000/storage/profiles/ could not be located (Error 404: Not

I have successfully implemented a feature on my website that allows users to upload their avatar picture using Vue.js and Laravel as the backend. The image is stored in the storage directory, and I can display it on the user's profile page using Vue.j ...

Exploring the dynamic duo of MongoDB and GridFS

We currently manage a large-scale project that accommodates thousands of users daily. Our database system is MySQL, but we are considering transitioning to MongoDB along with GridFS. Is it feasible to utilize MongoDB and GridFS for projects on this scale? ...

Personalize the start and end dates of Fullcalendar

While working with fullcalendar, I have a unique requirement. I want my days to start at 5:00 and end at 5:00 the next day. Is it feasible to achieve this customization? ...

The document.write function in JavaScript is malfunctioning

I've been attempting to utilize the javascript function document.write to incorporate an external css file in my template. However, I am aiming to achieve this using Twig, like so: document.write('<link href="{{ asset('bundles/activos/cs ...

Determine with jQuery whether the img src attribute is null

My HTML structure is as follows: <div class="previewWrapper" id="thumbPreview3"> <div class="previewContainer"> <img src="" class="photoPreview" data-width="" data-height=""><span>3</span> </div> </div> ...

NodeJS has a knack for replying even before the function has completed

Struggling with a NodeJS and Express API for a school project. The getAuthUserId function is not working as expected. It decodes the JWT token to retrieve the user Id from the mongoDB server. However, when calling this function in a REST call "/user/authT ...

I encountered a PrimeVue error while running a Vue Jest test

When working on a Vue jest test, I encountered an error message "No PrimeVue Confirmation provided!" which seemed to be related to the useToast() and useConfirm() services. "transformIgnorePatterns": [ "<rootDir>/node_modules/(?! ...

How I disabled scrollbars in my HTML/CSS while implementing the Progid Microsoft gradient

IMPORTANT: Please read the latest update at the end of the question! Check out this snippet from my HTML/CSS code: html { height: 100%; } body { height: 100%; margin: 0px; filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#6699 ...

Unable to perform a default import in Angular 9 version

I made adjustments to tsconfig.json by adding the following properties: "esModuleInterop": true, "allowSyntheticDefaultImports": true, This was done in order to successfully import an npm package using import * as ms from "ms"; Despite these changes, I ...

coding with javascript and css

Essentially, I am trying to add padding specifically to the left side of this code snippet: if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("livesearch").innerHTML=xmlhttp.responseText; document.getElementById("live ...

Distributing information to modules made of Polymer

Is there a way to create a single source for all data that my elements can utilize but not change (one-way data-binding)? How can I achieve this without using a behavior? I attempted the following in my code: <script type="text/javascript" src="/data. ...

Oops! Looks like we couldn't locate the request token in the session when attempting to access the Twitter API

Every time I attempt to connect to the Twitter API using Passport OAuth, an issue arises that redirects me to an error page displaying this message: Error: Failed to locate request token in session at SessionStore.get (/Users/youcefchergui/Work/ESP/socialb ...

"Implement a jQuery fade-in effect following a collective toggle action

After looping through the hidden elements, the $("span#slogan").fadeIn("slow"); does not execute. How can I ensure that the fadeIn is the last action to be performed? <style type="text/css> #hidden span{ display:none; float:left; font-siz ...

Tips on utilizing the identical template in ngIf

I need to display different templates based on certain conditions. For example: <template [ngIf]="item.url.indexOf('http') == -1"> <a class="ripple-effect" [routerLink]="[item.url]" *ngIf="isUserLoggedIn == true" > ...

I'm looking for a solution to reorganize my current state in order to display the image URL

My React component, which also utilizes TypeScript, is responsible for returning a photo to its parent component: import React, { useEffect, useState } from "react"; import axios from "axios"; export const Photo = () => { const [i ...

How to validate a <select> element with parsley.js when it is dynamically populated with an object?

I'm struggling to validate a <select> element in my form. With the help of knockout.js, I select a location which then populates the Service Point based on the Location chosen. However, when I try to validate the form using parsley.js after pres ...

Steps to duplicate a Select input and attach it to a div using Jquery

Recently, I was working on a Select input with the name "item" as an example. <select name="item"> <option value="1">1</option> <option value="2" selected="selected">2</option> <option value="3">3</option> <opt ...

The Asp button fails to initiate the function

One area of concern I have is with the signup page for my project, particularly regarding the following code: <input type="email" id="email" title="invalid email!" runat="server" placeholder="email" /> ...