Change product image on hover in product listing

  • Posts: 69
  • Thank you received: 4
10 years 9 months ago #156942

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: 10 years 9 months ago by niqui.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 9 months ago #156950

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.

  • Posts: 69
  • Thank you received: 4
10 years 9 months ago #157229

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.

  • Posts: 91
  • Thank you received: 5
7 years 6 months ago #276047

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

<span class="obrazek2">
	<?php echo $this->row->images[1]->file_path;?>
	</span>
in line 72

2) In CSS I added of course:
.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:
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.

  • Posts: 26205
  • Thank you received: 4032
  • MODERATOR
7 years 6 months ago #276058

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.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: shopshop

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

  • Posts: 13
  • Thank you received: 0
5 years 4 months ago #312254

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.

  • Posts: 83403
  • Thank you received: 13497
  • MODERATOR
5 years 4 months ago #312262

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.

  • Posts: 2
  • Thank you received: 0
3 years 7 months ago #334972

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: 3 years 6 months ago by Jerome. Reason: remove full quote of message #276047

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

  • Posts: 83403
  • Thank you received: 13497
  • MODERATOR
3 years 6 months ago #335304

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.106 seconds
Powered by Kunena Forum