backgroundPositionX not working on Firefox
Asked Answered
M

6

38

I have play with youtube's sprite animation but there is a problem. backgroundPositionX won't work under Firefox (but works on Chrome and IE8)... This is the code: https://jsfiddle.net/74RZb/

Extra info: the problem is that under firefox It doesn't change the background position (won't play the animation)... there are no errors, just doesn't change the background position.

Macdermot answered 19/12, 2012 at 8:55 Comment(0)
B
60

Firefox doesn't support backgroundPositionX, but it does support background position

So we can do something like this:

psy.style.backgroundPosition = x+'px 0';

This sets the background position, X first, then Y.

Working example here

Barbusse answered 19/12, 2012 at 9:2 Comment(3)
Thanks, I will click the "accepted answer" button once stackoverflow alows me :)Macdermot
Its right, but look at my answer its working fine from your answer. Your code is working slowly.Hopping
@Barbusse Yeah you are right. I also vote up your answer. Chill.. I tried your formula, but Its working slowly. So I changed it 60 to 30. Have a good day.Hopping
S
3

This works in IE, FF and chrome:

background-position: 0 center;

Sacaton answered 2/7, 2015 at 0:53 Comment(0)
C
2

This worked for me. NX is number of pixels in axis X and NY in axis Y.

background-position: calc(NXpx) NYpx;
Cornetcy answered 11/4, 2013 at 21:41 Comment(0)
B
1

Using like this:

background-position: calc(100% - 20px) center; // working on chrome and ff
background-position-x: calc(100% - 20px); // working on ie
Belamy answered 21/12, 2015 at 4:24 Comment(1)
When answering questions please provide explanation so that it can be more easily understood by other users of the site.Toluate
P
0

Background position-x can work in firefox you just have to specify a fixed background-y position. Here is a function I wrote to move a ribbon from left to right. At first it did not work when there was just a position-x specification, well it worked in IE but not FF. This was my solution. It is the actual code with comments from my site that works in both IE and FF:

   //starts ribbon motion at bottom of animation div 
    function startMotion() {
        var ribbonMove = setInterval(function () { ribbonMotion() }, 50);
        var x = 0;
        var cycles = 0;

        function ribbonMotion() {
            //background position moves on the x plane and is fixed at 0 on the y plane (single plane specification does not work in FF)
            document.getElementById("ribbon").style.backgroundPosition = x + "px" + " " + 0 + "px";
            x++;
            if (x == 800 || x==1600 || x==2400 ||x==3200) {
                cycles++;

              //sets number of cycles before motion stops (max 4 cycles)  
            }
            if (cycles == 3) {
                clearInterval(ribbonMove);
            }
        }
    }  
Pigfish answered 19/7, 2013 at 21:18 Comment(1)
doesn't work even if you set background-position-y in the CSSLonghand
E
0

You can do something like this

First install jquery migration

https://github.com/jquery/jquery-migrate/#readme

Include these on your html

The $.browser property allows you to target browsers you want to apply your style into

In this case for background-position can be changed to property supported backgroundPosition

Available flags are - webkit - safari - opera - msie (for IE) - mozilla

Example for IE or Firefox

if ( $.browser.msie || $.browser.mozilla) {
        $(".element").css('backgroundPosition', position + "px 0");                
}

for chrome

if ( $.browser.webkit) {
        $(".element").css('backgroundPosition', position + "px 0");                
}

I got mine working and for all IE

Cheers

Enphytotic answered 11/12, 2014 at 5:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.