jquery - 使用 jQuery 动画 div 背景

标签 jquery css jquery-animate

好的,所以我正在尝试使用 jQuery 为 DIV 元素背景图像制作动画,背景是一朵云,我想以缓慢的移动模式一遍又一遍地循环。知道我该怎么做吗?

我试过这段代码,但运气不好,所以不确定哪里出了问题。

$(document).ready(function() {

    $(function() {
    $.fn.extend({
    animateHeader: function(){
       $(this).find('#header').css('background-position', '0px 0px');
       $(this).find('#header').animate({
            backgroundPosition: '-20px 0px'
       }, 100, 'linear', function() {
            animateHeader(self);
       });
    }
    });
    });

    $(document).ready(function() {
    $(this).animateHeader();
    });

    });

附言它自己的背景图像是 1598 x 337px 如果有人感兴趣的话,这里是它的样子:http://i54.tinypic.com/25zng2r.jpg

最佳答案

默认情况下你不能,但你可以使用这个插件来实现你想要的结果: http://www.protofunc.com/scripts/jquery/backgroundPosition/

关于jquery - 使用 jQuery 动画 div 背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6905624/

相关文章:

css - "+"(加号)CSS 选择器是什么意思?

javascript - 做-webkit-filter : grayscale(100%); cause bugs?

jquery - 悬停动画后将边框移动到下一个 li

javascript - 为什么 jQuery 必须接收 2 个对象 : body & html when scrolling whole page with animation?

jquery - 实现addClass和removeClass之间的过渡效果

javascript - 如何使 if/else 语句评估所有变量

javascript - 将 div 从其位置动画到全屏

html - Bootstrap中元素的位置

jquery - $(this).animate({ 顶部 : 200 }, 500); TOP 是一个变量?

javascript - HTML5 必需的属性通过 jQuery 触发操作