SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Sep 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find the background-image height

    Hi all,

    I have this line of code in my body. How do I find the height of this image (ad_large.jpg) using javascript? Any help would be appreciated.

    <div id="myBgImg"; style="position:absolute; top:10; left:10; width:100%; height:100%; z-index:1; padding:0px; border: #000000 1px solid; background-image:url(images/ad_large.jpg);">

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code Javascript:
    var i = new Image();
    i.onload = function() {
      alert(this.height);
    }
    var bg = document.getElementById('myBgImg').style.backgroundImage;
    i.src = bg.replace('url(','').replace(')','');


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •