How to Implement Product Image Slider?

To enhance user experience and optimize site performance, a dynamic preview feature has been implemented for product images on the listing page.

This feature divides the main product image into three transparent, invisible zones that cover the entire image.

  • When the user moves the mouse cursor over the left section of the product image, the primary (first) image remains visible.

  • As the cursor transitions toward the center section, the second image is displayed.

  • Similarly, hovering over the right section reveals the third image.

This dynamic behavior ensures that the image corresponding to the cursor’s location is displayed seamlessly. When the cursor exits the product image, the default (first) image is automatically restored.

The number of invisible zones adapts dynamically based on the availability of product images:

  • For products with two images: The visual preview consists of two zones, allowing the same smooth transition between the images.

  • For products with a single image: This feature is not activated, and the primary image remains static.

  • For products with more than three images: The first three images are displayed using this dynamic preview, following the aforementioned logic.

This innovative functionality allows users to quickly explore multiple product images without navigating to the product detail page, significantly improving browsing efficiency while maintaining optimal site performance.

Technical Requirements and Prerequisites​

  • Compatibility: The feature is supported in @akinon/next versions between 1.43.0-rc.14 and 1.72.0.

  • Dependencies: The swiper package is required. Recommended version: 8.4.5.

Implementation Steps​

1. Create the Product Image Slider Component​

  • Navigate to the following folder: apps/projectzeronext/src/views/product-item

  • Create a file named product-image-slider.tsx.

  • Add the following code to the file to implement the slider:

This component:

  • Creates a slider with a maximum of three images if the product has multiple visuals.

  • Enables navigation between images when hovering over the product image.

2. Add Swiper Components​

If the Swiper components (swiper-react and swiper-slide) are not available in your project, add them as follows:

Create the swiper-react Component​

  • Navigate to apps/projectzeronext/src/components.

  • Create a file named swiper-react.tsx.

  • Add the following code:

Create the swiper-slide Component​

  • Navigate to apps/projectzeronext/src/components.

  • Create a file named swiper-slide.tsx.

  • Add the following code:

3. Update components/index.tsx​

To make the newly created components available across the project:

  • Open the apps/projectzeronext/src/components/index.ts file.

  • Add the following exports:

Last updated

Was this helpful?