Switch up your Wordpress gallery images with a simple mouseover trick!

Hey there! I need to create a grid of images for various products, where each item in the grid has 2-3 images but only the first one is visible initially. I want the other images to loop on mouse hover. Do you know how to do this in WordPress?

My initial idea was to use a gallery for each product and then only display the first image using CSS while hiding the rest. But now I'm not sure how to implement the slideshow effect on mouseover.

Does anyone have an alternative solution in mind?

Thanks in advance!

Answer №1

Based on the snippet provided, here is the CSS code that can achieve the desired outcome. I have included a wrapper div in the sample to act as the viewport, which will display one image at a time. Additionally, I have eliminated all
tags that clear the float because the CSS relies on float to exhibit images side by side for the slide effect.

<div id="viewport">
  <div id="gallery-1" class="gallery galleryid-20 gallery-columns-1 gallery-size-collection">
    <dl class="gallery-item">
        <dt class="gallery-icon portrait">
            <a data-lightbox-gallery="lightbox-gallery-1" href="image1.jpg" data-rel="lightbox-gallery-1">
                <img id="image1" style="border: medium none;" class="attachment-collection" alt="image1" height="420" width="300">
            </a>
        </dt>
    </dl>
    <dl class="gallery-item">
        <dt class="gallery-icon portrait">
            <a data-lightbox-gallery="lightbox-gallery-1" href="image2.jpg" data-rel="lightbox-gallery-1">
                <img id="image2" style="border: medium none;" class="attachment-collection" alt="image2" height="420" width="300">
            </a>
        </dt>
    </dl>
    <dl class="gallery-item">
        <dt class="gallery-icon portrait">
            <a data-lightbox-gallery="lightbox-gallery-1" href="image3.jpg" data-rel="lightbox-gallery-1">
                <img id="image3" style="border: medium none;" class="attachment-collection" alt="image3" height="420" width="300">
            </a>
        </dt>
    </dl>
  </div>
</div>

I have assigned unique ids to each image for distinct styling options using CSS.

Now, concerning the CSS rules:

/* STYLING FAKE IMAGES - NOT PART OF THE ACTUAL SOLUTION */

#image1{background-color: red;}
#image2{background-color: green;}
#image3{background-color: blue;}


#viewport{width: 300px; overflow: hidden;}
#gallery-1{width: 900px; height: 420px; white-space: nowrap;}
#gallery-1 dl{float: left; margin: 0;}

/* HOVER TRIGGER FOR ANIMATION USING KEYFRAMES TO SLIDE AND PAUSE */

#viewport:hover #gallery-1{
      -webkit-animation-name: slide;
      -webkit-animation-duration: 4s;
      -webkit-animation-timing-function: ease-in;
      -webkit-animation-iteration-count: infinite;     
}

 /* 4 SECOND ANIMATION WITH SPECIFIC PERCENTAGE VALUES TO EMULATE IMAGE PAUSES */

 @-webkit-keyframes slide
  { 
        0% { transform: translateX(0); }
        15% { transform: translateX(-300px); }
      35% { transform: translateX(-300px); }
      50% { transform: translateX(-600px); }
      70% { transform: translateX(-600px); }
      85% { transform: translateX(0); } 
      100% { transform: translateX(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

What is the best way to horizontally align an element within a Material UI Grid item?

How do I align elements in the center of a Material UI Grid item? Check out this code snippet from my React project: <Grid container> <Grid item xs={4}> // Other content goes here </Grid> <Grid item xs={4}> // How can ...

Prevent fixed element from scrolling beyond a specific point

I'm working on a fixed sidebar that needs to scroll along with the main content and stop at a specific point when scrolling down, and vice versa when scrolling up. I've created a script that calculates the window height, current scroll position ...

The Bootstrap Carousel is glitching and cannot be customized using HTML and CSS - I even included a demonstration gif

incorrect output: https://i.sstatic.net/6kwqT.gif When observing closely as the carousel transitions from almond 2 to almond 3, there is a slight jump that occurs. Despite multiple attempts, I have been unable to eliminate it. To demonstrate the issue, I ...

How to create a stunning pixel pattern overlay on a website section

I've been exploring how to add a pixel pattern overlay onto a website section similar to what's done on this site: (over the background video image at the top and the image in the bottom section). I'm sure it's a simple process, I jus ...

How to Customize a Horizontal Rule for Internet Explorer

Greetings, as I strive to create an image light website, I am interested in developing two-tone hr elements. I have successfully implemented this feature in modern browsers, but now I aim to achieve the same effect in ie6 and 7. The current code that I a ...

What is the correct way to adjust the style.top attribute of an element using JavaScript?

In order to correct a JavaScript source code, I need to adjust the style.top property of a div element based on an integer parameter from a function called index. Here is the current implementation: div.style.top = (index * 22 + 2)+"px"; However, for lar ...

What is the best way to center a CSS box on the screen?

I am attempting to center the login box on the screen, but when using position: absolute the background color changes to white. /* all */ .patua_font { font-family: 'Patua One', cursive; } .Roboto_font { font-family: 'Roboto&apo ...

What steps can I take to ensure that the full tingle modal, which includes an image, is visible when the

Upon loading the page, I noticed that if the browser width is greater than 540px, the modal displaying an image gets cut off (see figure below). What steps should I take to ensure that the vertical scroll bar appears immediately? https://i.sstatic.net/cJv ...

Display an image when the iframe viewport is reduced in size by utilizing media queries

I am looking to showcase a demo.html page within a 400px square iframe. When the viewport is smaller than 400px, I want demo.html to only display an image. Then, when clicking on that image in demo.html, the same page should switch to fullscreen mode. Sim ...

Ensure that two cells within the same row of two tables are equal in width

I have 2 tables in the same row of a large table, set up like this: <table> <tr> <td>Type</td> <td>Storage 1</td> <td>Storage 2</td> </tr> ...

Picture emerges from the lineup

My dilemma involves repositioning an image within a row > col-md-6. To address this, I devised two classes - .pos1 and .pos2 .pos1 { position: relative; } .pos2 { position: absolute; right: 0px; } However, when applying these classes, the ...

Assistance needed! Issue with the functionality of the survey modal text inclusion

Currently working on this page: The red bar is supposed to trigger a modal window with the survey inside. However, I am encountering an error in my .TXT file. <!--CSS--> There is additional code that I can't display due to restrictions from t ...

Issues with the card display within a Bootstrap carousel

Having encountered challenges with displaying cards in a bootstrap carousel, I am seeking assistance. To view my current (incomplete) project, please refer to the CodePen link below. https://codepen.io/robbiecorcoran/pen/eYMVvEN <!-- SEEKING ASSISTANCE ...

Enhance your website with a stylish CSS jQuery menu that lets you toggle, slide

If you're curious about the code, take a look here! Here are some of the issues I'm facing: The div doesn't toggle to hide when clicked on itself, only when another one is clicked. (UPDATE: it actually won't toggle at all) When t ...

Elements with absolute positioning are preventing drag events from executing

Struggling to create a slider and encountering an issue. The problem lies in absolute items blocking slider drag events. I need a solution that allows dragging the underlying image through absolute positioned items. Any ideas on how to achieve this? MANY T ...

Sideways movement of a single line within a table

Would you please help with a challenge I'm facing? I want to create a horizontally scrollable row that spans 100% of the page width without overflowing on top of the background image and while keeping the header text in focus. This is what I have att ...

Adjust the transparency of CSS elements using a jQuery selector

I am developing a grid of brand thumbnails with interactive icons. When one of the icons is hovered, I want all the icons to change opacity and become visible. Here is the current HTML structure: <div id="brands-wrapper"> <img class="brands" ...

Struggling to get Angular to properly load routes

I've been working on a local web page recently, following this helpful tutorial that shows how to integrate Django and Angular for user authentication. However, I've encountered an issue where the "register" button doesn't display anything e ...

Modify the URL for image attachments in WordPress

Currently working on developing a WordPress plugin that will automatically generate compressed images. I am looking for advice on the appropriate hook or action to use in order to replace the image URL with the compressed one when calling 'wp_get_atta ...

Ensuring that links are functional across all directory levels: a comprehensive guide

Looking at the image included here, you can see a preview of the website I'm currently building. The plan is to have individual pages for each machine in the company's lineup. Since the navigation bar and menu will be consistent across the entire ...