简体   繁体   中英

Error with div animate on scroll

Good evening, friends. Here is the site - http://p-karnaukhov.ru/ . On scroll this block http://joxi.ru/L21dE4XUQRkqmX must move to left to screen off. On scroll back it must come back to it's starting position. I already did scroll to left, but don't come back correctly. If we scroll more or less - block stay to wrong position.

jQuery(document).ready(function() {
    var lastScrollTop = 0;
    jQuery(window).scroll(function (event) {
        var st = jQuery(this).scrollTop();
        if (st > lastScrollTop) {
            jQuery('.flex-caption').animate({left: "-=20"}, 100);
        } else {
            jQuery('.flex-caption').animate({left: "+=20"}, 100);
        }
        lastScrollTop = st;
    });
});

Help me please resolve this problem.

I may be alone in this but I don't like jQuery. A sales pitch to make things easier often becomes burdensome code.

<script type="text/javascript">
function moveDiv(scrollamt) 
{
 var myDiv = document.getElementById('mydiv');
 var rightMargin = myDiv.style.marginRight;
 myDiv.style.marginRight = rightMargin+scrollamt;
}
</script>

<body onScroll="moveDiv(this.scrollTop);">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM