├── shirt.png ├── shirt2.png ├── script.js ├── style.css ├── index.html └── README.md /shirt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andrew-Tsegaye/Change-Product-Image-Color/HEAD/shirt.png -------------------------------------------------------------------------------- /shirt2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Andrew-Tsegaye/Change-Product-Image-Color/HEAD/shirt2.png -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | // Get elements from the DOM 2 | const color = document.querySelector(".color"); 3 | const colorInput = document.querySelector(".color-input"); 4 | 5 | // Add input event listener 6 | colorInput.addEventListener("input", () => { 7 | /*Set background of the color div to the color set in the input field*/ 8 | color.style.backgroundColor = colorInput.value; 9 | }); 10 | -------------------------------------------------------------------------------- /style.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: Helvetica, sans-serif; 4 | min-height: 100vh; 5 | display: flex; 6 | justify-content: center; 7 | align-items: center; 8 | gap: 2em; 9 | } 10 | 11 | .product { 12 | position: relative; 13 | box-shadow: 0 0 2em rgba(0, 0, 0, 0.2); 14 | border-radius: 1em; 15 | overflow: hidden; 16 | } 17 | 18 | .img-1 { 19 | width: 30em; 20 | z-index: 0; 21 | } 22 | 23 | .img-2 { 24 | position: absolute; 25 | top: 0; 26 | left: 0; 27 | width: 100%; 28 | z-index: 2; 29 | } 30 | 31 | p { 32 | max-width: 30em; 33 | line-height: 27px; 34 | } 35 | 36 | .color { 37 | background: red; 38 | position: absolute; 39 | top: 0; 40 | left: 0; 41 | width: 100%; 42 | height: 100%; 43 | z-index: 1; 44 | mix-blend-mode: multiply; 45 | } 46 | 47 | .color-input { 48 | background: #fff; 49 | border: 1px #ccc solid; 50 | border-radius: 4px; 51 | padding: 0.3em; 52 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |
16 |
17 |
18 |
19 | 24 | Lorem ipsum dolor sit amet consectetur adipisicing elit. Nemo, 25 | reprehenderit quas ea quo sed odit, quis iure consequuntur a ratione 26 | eligendi eum. Facere, quis. 27 |
28 | Customize shirt color: 29 | 30 |