Skip to main content

Change product image on hover in product listing

12 years 5 months ago - 12 years 5 months ago #156942 by niqui
Hi,

I was wondering if there is a way to change the product image on hover. I have created a menu item that shows a product listing (div) of a specific category. My customer would like it if the main product image changes to the second product image when hovering. For an example of the desired effect take a look at www.zoekarssenshop.com/highlited.html

Would that be very complicated to build?

Thanks for any ideas.
Last edit: 12 years 5 months ago by niqui.

Please Log in or Create an account to join the conversation.

12 years 5 months ago #156950 by Xavier
Hi,

You will have to edit the view "product / listing_img_title" and in the image part, add a Mysql request to get the other image path. Add another img tag with the second image link and apply a display:none; css property.

Then add javascript event on the images to hide the first one and display the other one when mouse over.

So if you have development skills in PHP, Javascript it will be easy, else there is some things to learn before doing that ;)

Please Log in or Create an account to join the conversation.

12 years 5 months ago #157229 by niqui
OK, thanks for the answer. I was afraid it would involve some knowledge of PHP and javascript. Maybe I'll try and see how far I get, but at least I can tell my client it's not that 'just a click on a button' to achieve this ;)

Please Log in or Create an account to join the conversation.

9 years 2 months ago #276047 by bolando
Hey,

I also needed that function and I found a solution. It works if you have more than one image for product and shows the second one:

1) In my template override
/html/com_hikashop/product/listing_img_title.php
I added
Code:
<span class="obrazek2"> <?php echo $this->row->images[1]->file_path;?> </span>
in line 72

2) In CSS I added of course:
Code:
.obrazek2 { display:none }

3) Than supposing you have 4 columns view and original images set as 420px x 420px (like in my case), you add a jQuery code to your template:
Code:
jQuery('.hkc-md-3.hikashop_product').each(function(){ var obrazek = jQuery.trim(jQuery(this).find('.obrazek2').text()); var obrazekOk = jQuery(this).find('img').attr('src'); if (obrazek.length > 15) { jQuery(this).find('img.hikashop_product_listing_image').mouseover(function(){ jQuery(this).css('width','182px').height('182px').attr('src','/new/images/com_hikashop/upload/thumbnails/420x420f/'+obrazek) }) jQuery(this).find('img.hikashop_product_listing_image').mouseout(function(){ jQuery(this).attr('src',obrazekOk) }) } })

Works fine.
The following user(s) said Thank You: shopshop

Please Log in or Create an account to join the conversation.

9 years 2 months ago #276058 by Jerome
Hello,

Thank you for sharing.

Regarding your code, it is really specific to your website (the hard coded URL with the prefix and the thumbnail size).
I think such kind of implement could be done using CSS2/3 rules ; but for sure it would require to display the second image using the HikaShop image helper ; and not just display the file_path of that image.

Regards,

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
The following user(s) said Thank You: shopshop

Please Log in or Create an account to join the conversation.

7 years 2 weeks ago #312254 by shopshop

Jerome wrote: Hello,

Thank you for sharing.

Regarding your code, it is really specific to your website (the hard coded URL with the prefix and the thumbnail size).
I think such kind of implement could be done using CSS2/3 rules ; but for sure it would require to display the second image using the HikaShop image helper ; and not just display the file_path of that image.

Regards,



Hi
Can I ask you for guidance on how to standardize the second image?


/new/images/com_hikashop/upload/thumbnails/420x420f/
The way it is said is not principled at all.
thnak you very much.

Please Log in or Create an account to join the conversation.

7 years 2 weeks ago #312262 by nicolas
Hi,

You basically need to change the line:
jQuery(this).css('width','182px').height('182px').attr('src','/new/images/com_hikashop/upload/thumbnails/420x420f/'+obrazek)
You need to replace 182px byt the width and height of the thumbnails on your listing and change the path /new/images/com_hikashop/upload/thumbnails/420x420f/ to the path where the thumbnails are on your website.
It will probably be something like that: /images/com_hikashop/upload/thumbnails/XXXxYYY/
You need ot go in the folder /images/com_hikashop/upload/thumbnails/ via FTP and look at the available folders.
Also, this code requires jQuery to be available on the page.
It's probable that you have it, but it could be possible you don't.

Please Log in or Create an account to join the conversation.

5 years 2 months ago - 5 years 2 months ago #334972 by Giannakopoulos
Hello, Does anyone know what does it take to imply this feature in the latest version of Hikashop?
Thank you all in advnce!
PS
I Tried the above solution but it doesn't work
Last edit: 5 years 2 months ago by Jerome. Reason: remove full quote of message #276047

Please Log in or Create an account to join the conversation.

5 years 2 months ago #335304 by nicolas
Hi,

We actually added that capability recently:
www.hikashop.com/home/blog/471-hikashop-4-4-3.html#multi
So no need to change any code.

Please Log in or Create an account to join the conversation.

Time to create page: 0.077 seconds
Powered by Kunena Forum