Jump to content

Selected Color - Highlight with CSS


Recommended Posts

In the color picker I'd like the border around the color swatch to darken once selected. Is this possible? For example, if the color "Pink" is selected, the border around the color swatch in the color picker would change to black, instead of remaining gray.

Thank you very much in advance.

Link to comment
Share on other sites

I don't understand. PrestaShop already does this by default. Here is the code in the /* product.tpl */ section of global.css that does it:

#primary_block a.color_pick {
   display: block;
   width: 20px;
   height: 20px;
   border: 1px solid #666;
   cursor: pointer
}
#primary_block a.color_pick:hover { border: 1px solid #000 }



The colours have a grey border (#666) that changes to black (#000) on hover.

Link to comment
Share on other sites

  • 1 year later...
  • 4 weeks later...

Hello all,

 

To Highlight the selected color, you just have to add those 2 lines in your js/product.js template:

 

Find

$('#color_'+id_attribute).fadeTo('fast', 1, function(){ $(this).fadeTo('slow', 0, function(){ $(this).fadeTo('slow', 1, function(){}); }); });

and remplace by

$('#color_to_pick_list .color_pick').removeClass('selected');
$('#color_'+id_attribute).fadeTo('fast', 1, function(){ $(this).fadeTo('slow', 0, function(){ $(this).fadeTo('slow', 1, function(){}); }); }).addClass('selected');

 

and in your css you just have to add this line:

#primary_block a.color_pick.selected {border:solid 2px}

 

Ckarone

Link to comment
Share on other sites

  • 1 month later...

This works well if the user selects color from the color picker. (Note for others: js file is in theme js folder not root js folder)

 

Unfortunately the color picker does not update if the user selects color from the drop down so you are left with the wrong color square selected.

 

Any ideas about how to get them to sync?

Link to comment
Share on other sites

  • 1 year later...

Did you ever find a solution for the issue that the color picker does not update if the user selects color from the drop down?

Having the same issue on my site.. Or does anyone else have a solution for me?

 

product.js code for the color picker:

function colorPickerClick(elt)
{
	id_attribute = $(elt).attr('id').replace('color_', '');
	$(elt).parent().parent().children().removeClass('selected');
	$(elt).fadeTo('fast', 1, function(){
								$(this).fadeTo('fast', 0, function(){
									$(this).fadeTo('fast', 1, function(){
										$(this).parent().addClass('selected');
										});
									});
								});
	$(elt).parent().parent().parent().children('.color_pick_hidden,#color_pick_hidden').val(id_attribute);
	findCombination(false);
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...