简体   繁体   English

jQuery背景位置y + = 1问题

[英]Jquery Background position y +=1 issue

Every 80 ms, I want to add += 1 to div 's background's Y position. 每80毫秒,我要在div的背景Y位置添加+= 1
The issue is that it doesn't work. 问题是它不起作用。 It only works if I add += 1 to x position. 仅当我在x位置加上+= 1时才有效。
How can I do this? 我怎样才能做到这一点?

My code: 我的代码:

<script>
    $(function(){
        setInterval(oneSecondFunction, 80);
        });


    function oneSecondFunction() {
        $( '#grille1' ).css( 'background-position', '0 +=1' );

            }
</script>

The background-position is a composite style consisting of the x and y position. background-position是由x和y位置组成的复合样式。 You can't use relative values on composite styles, you have to set them separately: 您不能在复合样式中使用相对值,而必须分别设置它们:

$('#grille1').css('background-position-y', '+=1');

However, not all browsers support the separate styles for the background position, so for maximum compatibility you would need to keep track of the position so that you can create the composite value, or parse the composite value and do the relative calculation yourself. 但是,并非所有浏览器都支持背景位置的单独样式,因此为了获得最大的兼容性,您需要跟踪位置,以便您可以创建复合值或解析复合值并自己进行相对计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM