当前位置: 动力学知识库 > 问答 > 编程问答 >

css - How to change the color of a item in a gallery

问题描述:

I'm trying to find out how to have a item change color when clicking different colors button.

Some thing like in the following site

http://www.imprintablefashion.com/cgi-bin/brand/site.w?location=olc/cobrand-product.w&category=3&prb=&srb=&mill=&shade=&color=&product=8398&frames=no&target=main&sponsor=004974&nocache=77902

I'm using WordPress. If anyone can point me to the right direction that would be great. Any

idea of examples would be greatly appreciated.

网友答案:

You actually need to have several images. Each time you press on item/button, you will change the image in the image place holder in your HTML to the desired one.

// JS
function changeImg()
{ 
    // some logic like swicth to select the image
    document.getElememtById("image_cont").innerHTML = "<img src='" + some_image + "'/>";
}
// Html
<div id="image_cont"></div>
<button onclick="changeImg()">Change the Image</button>

// so on

Then you can use some logic in your function to select the image you desire.

分享给朋友:
您可能感兴趣的文章:
随机阅读: