...

View Full Version : get the background position



Kor
08-07-2006, 03:19 PM
I have:


<!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
08-07-2006, 08:54 PM
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?

coothead
08-08-2006, 11:50 AM
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...

http://forums.mozillazine.org/index.php?sid=2039f462f242594d9874265894569d81
...if all else fails.
I am intrigued as to what the solution will be. :)

coothead

Kor
08-08-2006, 12:07 PM
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...

http://forums.mozillazine.org/index.php?sid=2039f462f242594d9874265894569d81
...if all else fails.
I am intrigued as to what the solution will be. :)

coothead
Tx, I have posted it in Moz's Forum :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum