Decreasing the browser window changes the position of the labels

0

I've created labels dynamically with a certain position. The problem is that when I minimize the browser its position changes. How can I fix this?

    //creation labels
    var labeltemp = document.createElement("Label");
    labeltemp.style.left = x2-10;
    labeltemp.style.top = y2+5;  
    labeltemp.style.position='absolute';

    var number = document.createTextNode(number);
    labeltemp.appendChild(number);

    document.body.appendChild(labeltemp);

Example: link

    
asked by anonymous 22.12.2014 / 15:02

2 answers

0

Using an element with position: fixed the position of it is relative to the non-graph window as you were expecting.

Fixed is used when you keep an element attached to a position, for example a header that will always stay on top even when you scroll through the page.

Description of fixed in MDN

I made an example in the jsfiddle that always stays in the expected position. link

    
29.12.2014 / 19:40
0

When you resize the margin and / or padding it is being reset. You can take the test using: * {   margin: 0;   padding: 0; }

Using position: fixed; will correct for IE.

    
22.12.2014 / 20:06