Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jquery设置方向动画_Javascript_Jquery_Css - Fatal编程技术网

Javascript 使用jquery设置方向动画

Javascript 使用jquery设置方向动画,javascript,jquery,css,Javascript,Jquery,Css,我用响应脚本创建了雪花。一切都很好,没问题。但是我想增强雪花的方向,比如从左到右,从右到左,从上到下。我试过了,但我不确定是哪里出的错 这是 Javascript: var fallingSpeed = Math.floor(Math.random() * 5 + 1); var movingDirection = Math.floor(Math.random() * 2); var currentTop = parseInt(jQ

我用响应脚本创建了雪花。一切都很好,没问题。但是我想增强雪花的方向,比如从左到右,从右到左,从上到下。我试过了,但我不确定是哪里出的错

这是

Javascript:

        var fallingSpeed = Math.floor(Math.random() * 5 + 1);
            var movingDirection = Math.floor(Math.random() * 2);
            var currentTop = parseInt(jQuery(this).css('top'));
            var currentLeft = parseInt(jQuery(this).css('left'));
            jQuery(this).css('top', currentTop + fallingSpeed);
      alert(currentLeft);
//
      //alert(movingDirection);
                if (movingDirection === 0) {
                    jQuery(this).css('left', currentLeft + fallingSpeed);
                } else {
                    // set the snow move to left
                    jQuery(this).css('left', currentLeft + -(fallingSpeed));
                }
如何将薄片从左向右和从右向左移动? 任何建议都很好


谢谢。

尝试jquery animate的
步骤
回调函数:

$(function(){
  var drop = $('.drop').detach();
  function create(){
    var clone = drop
      .clone()
      .appendTo('.container')
      .css('left', Math.random()*$(document).width()-20)
    .html('*')
      .animate(
                {'top': $(document).height()-20},
          {
              duration: Math.random(1000)+8000,
              complete:function(){
                 $(this).fadeOut(200,function(){$(this).remove();}); 
               },
              step:function (currentTop){
                                    var fallingSpeed = Math.floor(Math.random() * 5 + 1);
            var movingDirection = Math.floor(Math.random() * 2);
            var currentTop = parseInt(jQuery(this).css('top'));
            var currentLeft = parseInt(jQuery(this).css('left'));
            jQuery(this).css('top', currentTop + fallingSpeed);

                if (movingDirection === 0) {
                    jQuery(this).css('left', currentLeft + fallingSpeed);
                } else {
                    // set the snow move to left
                    jQuery(this).css('left', currentLeft + -(fallingSpeed));
                }
              }
          });
  }

是的,雪花……让我想起了90年代;)[HOT]请访问此url-