Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep z-index in canvas when updating images via select box
    primarykey
    data
    text
    <p>I'm building a poker table maker that works as follows:</p> <ol> <li>When the page loads, I load the components of a poker table one-by-one. </li> <li>Final users select what kind of felt, armrest, body or cup holders want on their poker tables through a select box. </li> <li>When a change is detected in the select box, the src attribute of the Image object changes as well. For example: If a user wants a black felt, I'm loading the image: felts/black.png; then if he decides that it looks better in blue, the page loads the image felts/blue.png</li> </ol> <p>My problem is the following:</p> <p>As soon as they change one element of the poker table, the new image is automatically loaded on top of the rest .</p> <p>For example: If I change the felt color, the felt's image will go on top of the armrest's image. </p> <p>I'd like to know how to force the felt image to maintain its z-index sort of thing. </p> <p>Here's my code:</p> <pre><code> var tableBody = new Image(); tableBody.onload = function() { context.drawImage(tableBody, 0, 0); }; tableBody.src = "http://www.mcptables.com/images/buildyourtable/body/autumn-oak.png"; /* and it does the same thing for the other parts of the poker table... tableArmrest, tableFelt tableCupholders, etc... */ $('#armrest').change( function() { switch( $(this).val() ) { case "black": tableArmrest.src = "http://www.mcptables.com/images/buildyourtable/armrest/black.png"; break; case "brown": tableArmrest.src = "http://www.mcptables.com/images/buildyourtable/armrest/wood.png"; } } ) </code></pre> <p>You can see it in action on the following page:</p> <p><a href="http://mcptables.com/buildyourtable.html" rel="nofollow">http://mcptables.com/buildyourtable.html</a></p> <p>And here's a link to my JS code:</p> <p><a href="http://mcptables.com/js/pokertablebuilder.js" rel="nofollow">http://mcptables.com/js/pokertablebuilder.js</a></p> <p>Any help would be greatly appreciated! If I want to change the </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload