image overlay and change on dropdown selection?


I'd like to make something of this kind where you can select the fore and background and make it display together. : <a href="https://www.control4.com/solutions/products/switches" rel="nofollow">https://www.control4.com/solutions/products/switches</a>

I do understand some things could be missing and I have tried to look around. I'd appreciate any help. Many thanks.

<div class="foreground"> <h4>Button Colour</h4> <select onchange="$('#imageToSwap').attr('src', this.options[this.selectedIndex].value);"> <option value="switch/button/white.png" selected>White</option> <option value="switch/button/snowwhite.png">Snow White</option> <option value="switch/button/biscuit.png">Biscuit</option> <option value="switch/button/lightalmond.png">Light Almond</option> <option value="switch/button/brown.png">Brown</option> <option value="switch/button/black.png">Black</option> <option value="switch/button/midnightblack.png">Midnight Black</option> <option value="switch/button/aluminum.png">Aluminum</option> </select> </div> <br> <div class="background"> <h4>Faceplate Colour</h4> <select onchange="$('#imageToSwap').attr('src', this.options[this.selectedIndex].value);"> <option value="switch/faceplate/white.png" selected>White</option> <option value="switch/faceplate/snowwhite.png">Snow White</option> <option value="switch/faceplate/biscuit.png">Biscuit</option> <option value="switch/faceplate/lightalmond.png">Light Almond</option> <option value="switch/faceplate/brown.png">Brown</option> <option value="switch/faceplate/black.png">Black</option> <option value="switch/faceplate/midnightblack.png">Midnight Black</option> <option value="switch/faceplate/aluminum.png">Aluminum</option> <option value="switch/faceplate/satinnickle.png">Satin Nickel</option> <option value="switch/faceplate/bronze.png">Venetian Bronze</option> <option value="switch/faceplate/stainlesssteel.png">Stainless Steel</option> </select> </div>

<!-- style --> <style type="text/css"> .background { position:absolute; z-index:1; left:125px; top:125px; float: right; } .foreground { position:absolute; z-index:auto; float: left; } #switch{ position: relative; } </style>


If you notice, those images are png and of same dimensions with perfectly positioned switch and background. so displaying one div inside another will overlap it perfectly as the snippet below

Something with jQuery, should get you going....

<pre class="snippet-code-js lang-js prettyprint-override">$(document).ready(function() { $('#switchSel').change(function() { var switchPic = $('.switch'); switchPic.removeClass(); switchPic.addClass('switch ' + $(this).val()); }) }) <pre class="snippet-code-css lang-css prettyprint-override">.back { background: url(https://www.control4.com/files/large/805347005e9b7ee87d4da29d56c9fa44.png); height: 575px; width: 361px; display: inline-block; } .brown { background: url(https://www.control4.com/files/large/61ba4092e170c22c3806a930ca7924f5.png); height: 575px; width: 361px; } .black { background: url(https://www.control4.com/files/large/251e9a5ac63b46f4acf8b09dbc5e17b7.png); height: 575px; width: 361px; } <pre class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div> <select id="switchSel"> <option value="black">black</option> <option value="brown">brown</option> </select> </div> <div class="switch black"> <div class="back"> </div> </div>


  • Invoice PDF or bill PDF with json and jsPDF
  • Line -> JSONArray jArray=new JSONArray(result); giving nullpointer exception
  • How to plot area between a predefined upper and lower bounds in ggplot2?
  • PHP create embed image from database position
  • Highcharts PhantomJS - Alternative Approach
  • UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
  • Is there a simple way to count occurences of one text string within another text string?
  • Finder Plugin in Snow Leopard
  • npm browserify version of jquery-select2 version 4.x
  • Parallelize an R Script
  • Facebook Like Button doesn't increment
  • C++ DLL Wrapper in vb.net Passing byte array of a byte array?
  • Can I convert bool in model to yes/no in a QComboBox
  • Why is RAM in powers of 2?
  • Entity framework 'include' including more than it should
  • glpk.LPX backward compatiblity?
  • Insert statement into SQL Server database
  • How to run Java in compatibility mode?
  • Using same onClick listener with more than one view
  • TypeError: Main.login is not a function
  • C++ boost::spirit parsing embedded languages
  • WPF: can I inherit a UserControl but provide no XAML?
  • How to Set wallpaper of image with its actual size?
  • UI-GRID column summation on checkbox change
  • Objective C IBOutlets
  • Simple Factory with reflection C#
  • Emit new line in Inno Setup preprocessor
  • AVCaptureSession VS UIImagePickerController camera preview
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • if some function is not optimized does it mean that all functions where it is declared are not optim
  • Creating PDF from TIFF image using iText
  • Hide HTML elements without javascript, only CSS
  • Django model inheritance, filtering models
  • Copy to all folders batch file?
  • Moving mysql files across servers
  • Android fill_parent issue
  • How to draw moving and Running sine wave chart using JFree chart in java?
  • jquery mobile loadPage not working
  • Properly structure and highlight a GtkPopoverMenu using PyGObject
  • How can I get HTML syntax highlighting in my editor for CakePHP?