Big picture does not display properly under firefox and chrome

Discussion in 'JavaScript' started by whosedomain, Jan 1, 2015.

  1. #1
    <div class="footer">
                 <img src="mypicture.jpg"  width="40" height="40" onmouseover="ShowFloatingImage(this, 150, 150);" />
    </div>
    
    <script>
    
    function GetAbsPosition(obj)
    {
    var curleft = 0, curtop = 0;
    do {
    curleft += obj.offsetLeft;
    curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
    return [curleft,curtop];
    }
    
    function ShowFloatingImage(image, width, height)
    {
    var id = "trailimageid";
    var newdiv = document.getElementById(id);
    if(newdiv == null)
    {
    newdiv = document.createElement('div');
    newdiv.setAttribute('id',id);
    newdiv.setAttribute('onmouseout', "HideElement('"+id+"');");
    document.body.appendChild(newdiv);
    }
    newdiv.innerHTML = '<img src='+image.src+ ' width='+(image.width + width) + ' height=' + (image.height + height) + ' />';
    
    var absPos = GetAbsPosition(image);
    newdiv.style.position = "absolute";
    newdiv.style.posLeft = absPos[0] - width;
    newdiv.style.posTop = absPos[1] - height;
    newdiv.style.display="block";
    }
    
    function HideElement(id)
    {
    var elem = document.getElementById(id);
    elem.style.display="none";
    }
    
    </script>
    Code (JavaScript):
    how to let the code run properly under chrome, and firefox as ie, pls?
     
    whosedomain, Jan 1, 2015 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    538
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    posLeft and posTop... ?
     
    hdewantara, Jan 2, 2015 IP
  3. 2WDH.com

    2WDH.com Active Member

    Messages:
    143
    Likes Received:
    3
    Best Answers:
    5
    Trophy Points:
    68
    #3
    Hi.

    Try to replace
    newdiv.style.posLeft = absPos[0] - width;
    newdiv.style.posTop = absPos[1] - height;
    Code (JavaScript):
    with
    newdiv.style.left = absPos[0] - width;
    newdiv.style.top = absPos[1] - height;
    Code (JavaScript):
     
    2WDH.com, Jan 2, 2015 IP
  4. Pigeon Yoga

    Pigeon Yoga Active Member

    Messages:
    52
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    63
    #4
    You could also try converting to jQuery which should normalize it for you.
    $('.class').left(amt);
    Code (markup):
    , etc.
     
    Pigeon Yoga, Jan 4, 2015 IP