jQuery. scrollPercent - after change to left + animation

Viewed 39

When i scroll down my element goes to right and when i scroll up it goes to the left. I don't want it to go left when I scroll down.

$(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
        });
    });
});

My css

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