Restricting thumbnail scrolling within the visible area in a jQuery/CSS Gallery/Slideshow

Is it possible to create a gallery slideshow feature where the selected thumbnail's image source will be displayed in the main image container?

I believe I can implement that part successfully. Currently, my challenge is defining the thumbnail scrolling area - I want it to display thumbnails and not empty spaces.

Below is the jQuery code:

function thumbs_slide(){
        var more_thumbs = jQuery('.more-thumbs');
        var less_thumbs = jQuery('.less-thumbs');
        var thumbnails = jQuery('.thumb-outer-container .thumbnails');
        var more_scroll = '-100%';
        var less_scroll = '100%';
        var out_scroll = thumbnails.css('top');

        more_thumbs.hover(function(){
            thumbnails.css('top',more_scroll)
        },function(){
            out_scroll = thumbnails.css('top');
            thumbnails.css('top',out_scroll);                   
        })

        less_thumbs.hover(function(){
            thumbnails.css('top',less_scroll);
        },function(){
            out_scroll = thumbnails.css('top');
            thumbnails.css('top',out_scroll);
        })
    }

    thumbs_slide();

CSS Style:

.single-product .load .images .thumb-outer-container {
float: right;
width: 20%;
max-width: 200px;
overflow: hidden;
position: relative;
border: 1px solid #d1d1d1;


.thumb-outer-container .thumbnails {
-moz-transition: all 5s ease-in-out;
-ms-transition: all 5s ease-in-out;
-o-transition: all 5s ease-in-out;
-webkit-transition: all 5s ease-in-out;
transition: all 5s ease-in-out;
}

.thumb-outer-container .more-thumbs,
 .thumb-outer-container .less-thumbs {
opacity: .85;
position: absolute;
z-index: 99;
right: 0;
left: 0;
height: 50%;

text-align: center;
cursor: pointer;

-moz-transition: all .05s ease-in-out;
-ms-transition: all .05s ease-in-out;
-o-transition: all .05s ease-in-out;
-webkit-transition: all .05s ease-in-out;
transition: all .05s ease-in-out;
}

.more-thumbs {
top: 0;
}

.more-thumbs::after {
    content: '\f077';
    font-family: FontAwesome;
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    border-bottom: 1px solid currentColor;
    background-color: rgba(249,249,249,.95);
    color: rgba(0,174,239,1);
}

.less-thumbs {
bottom: 0;
}

.less-thumbs::after {
    content: '\f078';
    font-family: FontAwesome;
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    border-top: 1px solid currentColor;
    background-color: rgba(249,249,249,.95);
    color: rgba(0,174,239,1);
}

.thumb-outer-container .more-thumbs:hover,
.thumb-outer-container .more-thumbs:focus,
.thumb-outer-container .less-thumbs:hover,
.thumb-outer-container .less-thumbs:focus {
    opacity: 1 !important;
}

.single-product .load .images img {
border: 0;
}

.single-product .load .images .thumbnails {
padding-top: 0 !important;
position: absolute;
top: 0;
right: 0;
left: 0;
}

.single-product .load .images .thumbnails a {
margin: 0 0 1px !important;
padding: 0 !important;
border: 0;
float: left !important;
display: inline-block !important;
width: 100% !important;
max-width: 200px !important;
}

.single-product .load .images .thumbnails a:hover,
.single-product .load .images .thumbnails a:focus {
    border-bottom: 0;
}

This is a WP site, I can provide more code if necessary. However, I believe the solution lies within my jQuery script.

Check out the sample link: -> gallery tab

Thank you, Matt

Answer №1

To resolve this issue, you can attach a `click` event to every image in the thumbnail slider to switch the main image when clicked. Here's an example of how you can achieve this:

$('.thumbnails a img').click(function() {
  $(".woocommerce-main-image").attr("src", $(this).attr("src"));
});

I trust this solution will be beneficial for you!

Answer №2

I found my solution within the jQuery variables.

I decided to switch less_scroll from '100%' to '0';

    var more_scroll = '-100%';
    var less_scroll = '0';

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

Oops! There seems to be a problem with inserting an image using

I am trying to insert multiple images with a loop when clicked. The images are named "0.jpg","1.jpg","2.jpg" etc. To achieve this, I am using an array with all the elements: {name: '1', result: 1, prefecture: "city", photo1: "0.jpg"}, and my l ...

Issues with Bootstrap 5 navbar-light and font style rendering on Edge browser

My website seems to be having compatibility issues with Microsoft Edge. While everything works fine on Chrome, the navbar classes "navbar-light" and "bg-light" do not apply properly in Edge, and the font style defaults. I am using Bootstrap 5 and webfonts ...

Turn off the CSS hover effect for a custom button if the ng disabled attribute is set to true

My goal is to disable custom buttons, and the disable(pointer) function is working correctly. The issue arises when we try to hover on the button, as the hover effect still works. I therefore need to disable hover as well. I am looking to apply ng-disabl ...

Is it possible to reverse the effects of @media queries for min/max width and height?

I rely on http://www.w3.org/TR/css3-mediaqueries/ to customize my design based on the available viewport size. When I need to adjust the breakpoints, I struggle with negating @media (min-width: 500px), which overlaps with (max-width: 500px). To counter th ...

Angular components are not properly adhering to the specified height and width dimensions for child elements

I seem to be having trouble applying height/width to a child component in angular. Can someone take a look and point out where I may have gone wrong? app.component.html <app-child [width]="10" [height]="10"></app-child> .child.ts import { C ...

Change hyperlink text color on Android CheckBox

I am having a CheckBox with two links embedded in the text. The text is set using the following code: String htmlText = "Accept <a href='someUrl'>Terms and Conditions</a> and <a href='anotherUrl'>Privacy Policy&l ...

Exploring ways to customize the input color of Material UI TextField when it is disabled [Version: 5.0.8]

I am having trouble changing the border color and text color when an input is disabled. I have tried multiple variations, as seen below: const textFieldStyle = { '& label': { color: darkMode?'#1976d2':'', } ...

Using multiple selectors in JQuery and Javascript

I have a challenge where I need to execute different actions for specific divs. Here is the code snippet I currently have: $("#pending-cancel-1, #pending-cancel-2").click(function(){ Do something special for pending-cancel-1 and pending-cancel-2... }) ...

Issues with CSS not being applied when the page content exceeds the viewport

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Unique Title</title> <style> #div1 { posit ...

Instead of only one menu icon, now there are three menu icons displayed on the screen. (Additionally, two more divs containing

When visiting on a smartphone browser, you may notice that instead of one menu icon, three icons appear. Upon inspecting the elements, you will find that there are three div's that look like this: <div class="responsive-menu-icon">&l ...

The method for transforming all headers into permalinks with jquery/javascript

I am looking for a way to transform all headers on a page into clickable permalinks using jQuery or JavaScript. Here is the HTML code: $('h3').each(function() { var id = $(this).attr('id'); if (id) { //Check if the element has a ...

The issue of batch-wise data clustering on Google Maps when zooming in or out

//The code snippet provided below initializes a map with specified settings and clusters markers based on the data sent in patches of 10000.// var mapDiv = document.getElementById('newmap'); map = new google.maps.Map(mapDiv, { center ...

An unexpected error has occurred in the browser console: The character '@' is not valid

I recently made the decision to dive into learning about Unit Testing with JavaScript. To aid in this process, I started using both Mocha.js and Chai.js frameworks. I downloaded the latest versions of these frameworks onto my index.html from cdnjs.com. How ...

Discover the method to retrieve HTML content by sending an HTTP POST request in AngularJS, similar to loading content

My attempt to retrieve HTML content using Angular Js Post HTTP method was successful, but only for text contents like P tags. I am now trying to fetch HTML contents that include input types such as text boxes using Angular JS. Interestingly, when I utilize ...

Tips on customizing the navigation bar color in Bootstrap

Is there a way to update the CSS in Bootstrap 4 to customize the color of the navbar? I'm having issues with my code. Can you take a look at it? <nav class="navbar navbar-expand-lg navbar-dark bg-transparent"> <div class="container"> ...

I need to verify that the input type for time is valid, starting from today's date and extending beyond the current

<input type="date" onChange={(e)=>setDate(e.target.value)}/> <input type="time" onChange={(e)=>setTime(e.target.value)} /> If the selected date is after today and the time is after the current time, display a valida ...

add text above and below a button in a Button style

Just delving into HTML and CSS, I've created a button with the following styling: .Btns { width:200px; height:75px; background-color:lightblue; color:black; font-weight:bold; ...

What is the best way to use a computed property as a style value for a component in Vue.js?

My component's template includes the following HTML element: .grid-item(:style="{ width: columnWidth, backgroundColor: 'blue' }") I want to dynamically set the width of this element using a computed property: computed: { columnWidth () ...

Test your knowledge of Javascript with this innerHtml quiz and see

How can I display the output of a score from a three button radio button quiz without using an alert popup? I want the output to be displayed within a modal for a cleaner look. I tried using InnerHTML but now there is no output when the button is clicked. ...

How can JQuery's .load() method be best utilized when working with an image?

I am currently utilizing the .load() function to fetch an image from the server once a button on my webpage is clicked. I then wrap the image in "a href" and "img" tags to convert it into a clickable link, and finally attach it to a div. Here is the code ...