0

I have a value that emits an incrementing decimal value on scroll from 0 to 1.

Currently the script triggers the change of image on scroll as a scroll will cause the value to increment and the image will only change back once the value returns to 0.

I need a check that actively checks if the value is increasing and if the value stops increasing it should return to the idle image.

'

<script type="text/javascript">
var Character = document.getElementById("character");

(function($) {
    $.jInvertScroll(['.scroll'],        
        {
        height: 6000,                   
        onScroll: function(percent) {   
            console.log(percent);
            if (percent++) {
                Character.style.backgroundImage = "url(/examples/images/gif/sqeekiWalk.gif)";
            } else {
                Character.style.backgroundImage = "url(/examples/images/gif/sqeekiIdle.gif)"
            }
        }
    });
}(jQuery));

</script>

'

DarkRob
  • 3,843
  • 1
  • 10
  • 27
Luke
  • 23
  • 8
  • Could you try `if (percent > 0)` – Keith Aug 27 '19 at 09:42
  • Possible duplicate of [How can I determine the direction of a jQuery scroll event?](https://stackoverflow.com/questions/4326845/how-can-i-determine-the-direction-of-a-jquery-scroll-event) – misorude Aug 27 '19 at 09:45
  • 2
    Side note, `if (percent++)` may not be doing what you expect, `++` after a number will increment it, but **will not** return the new value. You'd need `if (++percent)` if you're trying to check the incremented number. – DBS Aug 27 '19 at 09:48
  • Possible duplicate of [How can I debug my JavaScript code?](https://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code) – Liam Aug 27 '19 at 12:29

0 Answers0