从上到下循环移动背景图像

时间:2022-11-11 12:38:51

I need to change this javascript, it should moving from top do down!

我需要更改这个javascript,它应该从顶部向下移动!

<script>
    $(function(){
        var x = 0;
        setInterval(function(){
            x-=1;
            $('body').css('background-position', x + 'px 0');
        }, 10);
    })
</script>

body {
    background-image: url('img/bg-body.jpg');
    background-repeat: repeat-x;
    background-size: 100% 100%;
}

Thank you guys! P.S.: Here is the link where I find it: enter link description here

感谢你们! P.S。:这是我找到它的链接:在这里输入链接描述

3 个解决方案

#1


0  

change x + 'px 0' to '0 ' + x + 'px'

将x +'px 0'更改为'0'+ x +'px'

when working with css properties that specify xy positioning, the first number is always on the horizontal ruler (x) and the second one on the vertical ruler (y)

使用指定xy定位的css属性时,第一个数字始终位于水平标尺(x)上,第二个数字始终位于垂直标尺(y)上

#2


0  

Pretty simple. What sets the position? You'll notice that x get's decremented with every loop. To make it go the other way, just increment it:

很简单。什么定位?你会注意到每个循环都会减少x get。为了让它走另一条路,只需增加它:

<script>
$(function(){
    var x = 0;
    setInterval(function(){
        x+=1;
        $('body').css('background-position', x + 'px 0');
    }, 10);
})
</script>

#3


0  

Demo: http://jsfiddle.net/7fa0jjzq/show

Code:

$(function(){
        var x = 0;
        setInterval(function(){
            $('body').css('background-position','0'+--x + 'px');
        }, 10);
})

Explanation:

change css `repeat-y', and change in jquery x to 0, as don't want to animate y, and change x to x variable.

更改css`repete -y',并将jquery x更改为0,因为不想为y设置动画,并将x更改为x变量。

#1


0  

change x + 'px 0' to '0 ' + x + 'px'

将x +'px 0'更改为'0'+ x +'px'

when working with css properties that specify xy positioning, the first number is always on the horizontal ruler (x) and the second one on the vertical ruler (y)

使用指定xy定位的css属性时,第一个数字始终位于水平标尺(x)上,第二个数字始终位于垂直标尺(y)上

#2


0  

Pretty simple. What sets the position? You'll notice that x get's decremented with every loop. To make it go the other way, just increment it:

很简单。什么定位?你会注意到每个循环都会减少x get。为了让它走另一条路,只需增加它:

<script>
$(function(){
    var x = 0;
    setInterval(function(){
        x+=1;
        $('body').css('background-position', x + 'px 0');
    }, 10);
})
</script>

#3


0  

Demo: http://jsfiddle.net/7fa0jjzq/show

Code:

$(function(){
        var x = 0;
        setInterval(function(){
            $('body').css('background-position','0'+--x + 'px');
        }, 10);
})

Explanation:

change css `repeat-y', and change in jquery x to 0, as don't want to animate y, and change x to x variable.

更改css`repete -y',并将jquery x更改为0,因为不想为y设置动画,并将x更改为x变量。