覆盖!重要的javascript / jQuery for animate()

问题描述 投票:2回答:1

我想为background-position-x设置动画,但它在css中有一个我无法删除的background-position: 0 0 !important;。用javascript有什么方法吗?我看到我的jQuery代码正在做它的工作,只是css值覆盖了它。

我用谷歌搜索,但似乎我无法添加!important到我的动画功能。

//编辑。或者甚至更好,如果我可以用纯css做到这一点?

谢谢!

jQuery(document).ready(function($) {
  $('.section').animate({
    'background-position-x': '100%'
  }, 100000, 'linear');
});

//编辑2.这实际上似乎有效:

@-webkit-keyframes animatedBackground {
  from {
    background-position: 0px 0px; }

  to {
    background-position: 100% 0px; } 
}

.section {
  -webkit-animation: animatedBackground 200s linear infinite;
  -moz-animation: animatedBackground 200s linear infinite;
  animation: animatedBackground 200s linear infinite; 
}

//编辑3.实际上,看起来FF仍然覆盖了!important并且在关键帧块内添加!important没有任何效果。想法?谢谢!

javascript jquery css
1个回答
0
投票

这最终为我工作。我还加了50%让它反弹!

@-webkit-keyframes animatedBackground {
  from {
    background-position: 0px 0px; }

  50% {
    background-position: 100% 0px; } 

    to {
    background-position: 0px 0px; }
}

.section {
  -webkit-animation: animatedBackground 200s ease infinite;
  -moz-animation: animatedBackground 200s ease infinite;
  animation: animatedBackground 200s ease infinite; 
}
© www.soinside.com 2019 - 2024. All rights reserved.