Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Question get the background position

    I have:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <style type="text/css">
    <!--
    body {
    	background-image: url(00.jpg);
    	background-repeat: no-repeat;
    	background-position: top left;
    }
    -->
    </style>
    <script type="text/javascript">
    function getStyle(obj,att){
    for(var i=0;i<att.length;i++){
    if(window.getComputedStyle){
    obj[att[i]]=window.getComputedStyle(obj,null)[att[i]];
    }
    else if(obj.currentStyle){
    obj[att[i]]=obj.currentStyle[att[i]];
    }
    }
    }
    
    onload=function(){
    var obj = document.getElementsByTagName('body')[0];
    var att=['backgroundImage','backgroundRepeat','backgroundPosition']
    getStyle(obj,att)
    for(var i=0;i<att.length;i++) {alert(obj[att[i]])}
    }
    </script>
    </head>
    <body>
    
    </body>
    </html>
    Works ok, both in IE and Moz as expected. With one exception, the backgroundPosition. No matter if I use top left or px values or % proportion, I can not get those values.

    Does anyone know how to get the backgroundPosition values from a class?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    and I am also intrigued by the Moz's return when i simply use
    var att=['background']

    Anyway...

    Is it a bad implementation in javascript of the CSS's attributes? Do they need another camelcase (
    for instance, in case of IE, following my first code, if i use

    var att=['backgroundImage','backgroundRepeat','backgroundPositionX']

    I get the correct answer : "left"

    But Moz do not so... Now what?
    Last edited by Kor; 08-07-2006 at 08:59 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,869
    Thanks
    0
    Thanked 268 Times in 263 Posts
    Hi there Kor,

    I thought that you might be interested to know that your code works OK in Opera 9.00.
    And you have found a solution for IE.
    You could try posting your problem here...
    ...if all else fails.
    I am intrigued as to what the solution will be.

    coothead

  • #4
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by coothead
    Hi there Kor,

    I thought that you might be interested to know that your code works OK in Opera 9.00.
    And you have found a solution for IE.
    You could try posting your problem here...
    ...if all else fails.
    I am intrigued as to what the solution will be.

    coothead
    Tx, I have posted it in Moz's Forum
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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