Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6858115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:07:01+00:00 2026-05-27T02:07:01+00:00

Im new to javascript so im sure there is a lot i am missing

  • 0

Im new to javascript so im sure there is a lot i am missing in its understanding.
What i am trying to do it create a layer of images so that it looks like a pile of cards.

have seen similar codes and have tried to follow their idea but i just cant get the images to position properly. All 10 or so images are place in the exact same location.

Can any help to see why they not positioning? Also what is “em”. I cant find any literature on it but assume it is the measurement em like px ?? Why is it in “” ?

function Display() {
var el;
var left = 0;
var top = 0;
var i=0;
var n = deck.length;
var cardNode;
var img = document.createElement("IMG");
img.src = "wendell7_back.png";
el = document.getElementById('deck');
el.appendChild(img);
while (el.firstChild != null) el.removeChild(el.firstChild);
for (i = 0; i < Math.round(n / 5); i++) 
{
    cardNode = document.createElement("DIV");
    cardNode.appendChild(img);
    cardNode.style.left = left + "em"; 
    cardNode.style.top  = top + "em";
    el.appendChild(cardNode);
    left += 0.1;
    top  += 0.1;
}

   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:07:01+00:00Added an answer on May 27, 2026 at 2:07 am

    “em” is the width of an “M” in whichever font is being used (or browser’s default font if nothing overrides it).

    There are at least two things wrong in your code:
    left and top have no meaning unless the element to which they are applied also has position:absolute or position:relative (or position:fixed I think). Your safest approach is to apply position:relative (but no left: or top:) to the container and position:absolute to each of the cards.
    There’s only one img. For multiple cards, you need multiple imgs otherwise the same img gets repositioned over and over.
    A more economical approach is probably to show a separate “stack” image for multiple cards and single card images for a single cards.

    An even more economical approach is only to show single card images with a “tooltip” to indicate the number of cards in a stack. I have successfully employed this technique in an implementation of a game of patients.

    Of course, these alternative techniques don’t work if you want to show multiple cards as a “fanned out” stack of upturned cards.
    Create a class and modify the position of that for the deck. Here is the working code:

    function Display() {
    var el;
    var left = 0;
    var top = 0;
    var i=0;
    var n = deck.length;
    var cardNode;
    el = document.getElementById('deck');
    while (el.firstChild != null) el.removeChild(el.firstChild);
    for (i = 0; i < Math.round(n / 5); i++) 
    {
        cardNode = document.createElement("DIV");
        cardNode.className = "card2";
        var img = document.createElement("IMG");
        img.src = "wendell7_back.png";
        cardNode.appendChild(img);
        cardNode.style.left = left + "em"; 
        cardNode.style.top = top + "em";
        el.appendChild(cardNode);
        left += .1;
        top  -= 6.2;
    }
    
    }
    

    Hope this will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to spawn a new window via javascript in IE7 that
New to javascript, but I'm sure this is easy. Unfortunately, most of the google
I'm relatively new to Javascript and was wondering if there's a quick way to
I'm new at javascript and while there are many more complex solutions, I don't
I'm absolutely new to JavaScript and would like to modify a textarea of a
I'm new to web development, I'm sure there's a simple answer to this, but
I'm new to JavaScript and I'm trying to get a slideshow working in my
New to ASP and probably never named a Javascript file .inc :-) But that
I was checking out HTML5 new javascript commands and there is something similar to:
I have an iframe Facebook application (using Facebook's new JavaScript API) that needs to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.