backgroundPositionX not working on Firefox

前端 未结 6 1770
感情败类
感情败类 2020-12-10 10:33

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

6条回答
  •  天命终不由人
    2020-12-10 10:46

    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);
                }
            }
        }  
    

提交回复
热议问题