Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.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
jQuery。滚动百分比-更改为左侧后+;动画_Jquery_Scroll_Jquery Animate - Fatal编程技术网

jQuery。滚动百分比-更改为左侧后+;动画

jQuery。滚动百分比-更改为左侧后+;动画,jquery,scroll,jquery-animate,Jquery,Scroll,Jquery Animate,当我向下滚动时,元素向右移动,当我向上滚动时,元素向左移动。当我向下滚动时,我不希望它向左移动 $(document).ready(function () { var $horizontal = $('.train'); $(window).scroll(function () { var x = $(this).scrollTop(), y = $(document).height(), i = $(this).

当我向下滚动时,元素向右移动,当我向上滚动时,元素向左移动。当我向下滚动时,我不希望它向左移动

$(document).ready(function () {
    var $horizontal = $('.train');

    $(window).scroll(function () {
        var x = $(this).scrollTop(),
            y = $(document).height(),
            i = $(this).height();

        scrollPercent = (x / (y - i));

        var position = (scrollPercent * ($(document).width() - $horizontal.width()));

        $horizontal.css({
            'left': position
        });
    });
});
我的css

 position: absolute;
  width: 375px;
  height: 221px;
  background:url(../1920/train.png)no-repeat;
  top: 2950px;
  z-index: 21;