473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get (currentstyle or getComputedStyl e.getPropertyVa lue) background-position in Firefox ? (works for IE & O)

I would like to obtain the the position of backgroundimage of a div because
I use it for animation. The following code works for Internet Explorer
(takes the else if) and returns positionx '10px' and position y '25px' (the
backgroundPosit ion doesn't work). Opera follows the first road (if) and
returns '10px 25px'. Firefox follows the same road (first if) as Opera but
returns a blank.

if (window.getComp utedStyle) {
var stijl = document.defaul tView.getComput edStyle(arrSlic es[10], '');
// var stijl = window.getCompu tedStyle(arrSli ces[10], '');
var backpos = stijl.getProper tyValue('backgr ound-position');
alert(backpos);
} else if (arrSlices[10].currentStyle) {
var backposx = arrSlices[10].currentStyle.b ackgroundPositi onX;
var backposy = arrSlices[10].currentStyle.b ackgroundPositi onY;
alert ('posx = ' + backposx + ' & posy = ' + backposy);
} else {
alert('Your browser does not support this shit!');
}

If I replace background-position with 'width' even Firefox returns a result.

thanx,

Pugi!
Mar 15 '06 #1
2 16765
Pugi! wrote:
^^^^^
Who?
I would like to obtain the the position of backgroundimage of a div
because I use it for animation. The following code works for Internet
Explorer (takes the else if) and returns positionx '10px' and position y
'25px' (the backgroundPosit ion doesn't work). Opera follows the first road
(if) and returns '10px 25px'. Firefox follows the same road (first if) as
Opera but returns a blank.

if (window.getComp utedStyle) {
var stijl = document.defaul tView.getComput edStyle(arrSlic es[10], '');
// var stijl = window.getCompu tedStyle(arrSli ces[10], '');
You should decide what you want to use: window.getCompu tedStyle() or
document.defaul tView.getComput edStyle()? Apparently both refer to the
same method in the Gecko DOM, meaning that `document' implements the
DocumentView interface, and `window' implements the AbstractView
interface of W3C DOM Level 2 Views. Since `window' refers to the
Global Object in that DOM, you could use only `getComputedSty le'; you
would have to replace the type-converting test by a proper feature test
(typeof ... == "function") anyway. Not everything that exists can also
be called.

However, using the empty string as value of the second argument of
ViewCSS::getCom putedStyle() is not standards compliant. It has to be
`null' (which works in Opera 8.51/Linux, too):

<URL:http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSview-getComputedStyl e>
var backpos = stijl.getProper tyValue('backgr ound-position');
However, you will observe that Firefox (1.5.0.1/Linux) returns a
ComputedCSSStyl eDeclaration object either way, not a CSSStyleDeclara tion
object as the standard calls for. This object has a getPropertyValu e()
method, however it does not need to work according to the
CSSStyleDeclara tion interface.

However, the object also has a `backgroundPosi tion' shortcut property
with the empty string as its value even if the CSS property value is
different (while its other shortcut properties have the value
getPropertyValu e() returned if the corresponding property name was
used as its argument), which is clearly a bug. See below.
If I replace background-position with 'width' even Firefox returns a
result.


<URL:https://bugzilla.mozill a.org/show_bug.cgi?id =316981>

(found as the most relevant hit for a quick search for
"background-position" on <URL:https://bugzilla.mozill a.org/>)
HTH

PointedEars
Mar 17 '06 #2
Thomas 'PointedEars' Lahn said the following on 3/17/2006 2:24 PM:
Pugi! wrote:
^^^^^
Who?


That would be "Pugi!". Can you not read a Poster's name anymore?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 18 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3635
by: Michael Rozdoba | last post by:
I want to set a background colour on one level of headings, but have their width span only the text & a small amount of padding. I was styling display to inline to achieve this. Then I realised I need to have clear: left, to keep the headings against the lefthand side, should they come near floats. I can't see how to do this without...
4
26560
by: Ghyslaine Crespe | last post by:
Hello, In my script, the line document.getElementById(id).style.background-position = "-200px -500px"; fails ! So, how can I change the background-position value ?
14
3607
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good readibility on browsers w/o css-support. For important notes, warnings etc I use the <pre> tag, which shows in a neat bordered box when viewed...
14
7376
by: arteccentrix | last post by:
Please bear with me as I am new to both Firefox and CSS. I have browsed through a number of groups looking for similar problems to my own but can't find a definitive answer. If anyone here can help me out I would appreciate your shared expertise so much. My background image is displaying fine in IE, and, sometimes in Firefox until I hit the...
2
4135
by: rapsody | last post by:
Hi, Ih ave a div tag with a backgound image as 320px and 2 div tags inside the main tag one floating left the other right. In each of the 2 div the height is expandable so may go over the 320px, in IE if either of the divs goes over the 320px the background colour that is set appears in firefox it doen't the style for the main div is ...
2
2195
by: soulmach | last post by:
Hello forum friends. I performed a search on this topic, but I couldn't find anything useful. I wasn't really sure what to search. First I'll state what I am trying to do. I recently agreed to make a site for a friend. It's good practice for me. The site will have (among other things) a biography. I told him to look at Zen Garden and find...
3
3579
by: tor.brekke.skjotskift | last post by:
I want to set a background-image with an id and use class to create the rollover effect by altering background-position. It wont work in either IE or FF. Any suggestions? HTML <a href="#" id="knappKalender" class ="knapp" (...) CSS
2
2735
by: rigiditymodulus | last post by:
Hi - So, I had this working perfectly, then had a small crash (the transmitter for my wireless mouse occassionally freaks out my MacBook Pro) and when I rebooted and opened up my file the two layered DIVs I had were no longer showing up correctly. I had this going fine for several hours -- it wasn't a happy accident I forgot to save. I'm...
10
5743
by: VividWeb | last post by:
Hi. I am relatively new to CSS and HTML but have a basic understanding of most things. One of my backgrounds is not positioning correctly in IE 7 or AOL. The background behind the content (small chocolate area) is positioning slightly down the page instead of at the top. I have used the same techniques in the navigation and it positions...
0
7484
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7415
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7440
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5997
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.