【问题标题】:JQuery Animation: Animate DIV left to right at different speed than top to bottomJQuery Animation:以不同于从上到下的速度从左到右动画DIV
【发布时间】:2014-04-19 18:31:00
【问题描述】:

尝试以一定的速度从左到右(和后退)为 1 个 DIV 设置动画,并以不同的速度从上到下(和后退)对其进行动画处理(本质上是创建类似窗口的屏幕保护效果)。

问题是每个动画一个接一个发生(很明显),但我一直在尝试组合,以便图像对角线动画。

来自 CSS 动画,这很容易,但它无法检测响应式窗口的宽度/高度,因此反弹边缘变得非常不稳定。

有什么想法吗?非常感谢。

目前的代码是:

$(document).ready(function() {

    updateWindowsize();
    $(window).resize(function() {
        updateWindowsize();
    });
    bounceBounce();

});

var imageWidth = '540'
    imageHeight = '705'

function updateWindowsize() {
    var $window = $(window);
    windowHeight = $window.height();
    windowWidth = $window.width();
}

function bounceBounce() {

    $('.div-1').animate({"left": windowWidth - imageWidth}, 3000, 'linear',
          function(){ $(this).animate({left: 0}, 3000, 'linear');
    });

    $('.div-1').animate({"top": windowHeight - imageHeight}, 6000, 'linear',
          function(){ $(this).animate({top: 0}, 6000, 'linear');
    });

    bounceBounce();

};

【问题讨论】:

    标签: javascript jquery html animation


    【解决方案1】:

    你试过了吗:

    $('.div-1').animate({"left": windowWidth - imageWidth, "top": windowHeight - imageHeight}, 6000, 'linear',
          function(){ $(this).animate({left: 0, top: 0}, 6000, 'linear');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-16
      • 2011-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 2014-01-26
      相关资源
      最近更新 更多