Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-07-2006, 03:19 PM   PM User | #1
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 08-07-2006, 08:54 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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?
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

Last edited by Kor; 08-07-2006 at 08:59 PM..
Kor is offline   Reply With Quote
Old 08-08-2006, 11:50 AM   PM User | #3
coothead
Senior Coder

 
coothead's Avatar
 
Join Date: Jan 2004
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 1,551
Thanks: 0
Thanked 195 Times in 191 Posts
coothead will become famous soon enough
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....74265894569d81
...if all else fails.
I am intrigued as to what the solution will be.

coothead
coothead is offline   Reply With Quote
Old 08-08-2006, 12:07 PM   PM User | #4
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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...
http://forums.mozillazine.org/index....74265894569d81
...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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:14 AM.


Advertisement
Log in to turn off these ads.