jquery - Javascript variables for current scroll position and previous scroll postion -


I'm trying to determine whether the user has scrolled up or down and I've got some code that is helpful I think I'm out My problem with this code is that I can not wrap my head to capture last_scroll_position . I have a function for return scrollTop so that variable < Getting value for code> current_position is not a problem, but obtaining values ​​for last_scroll_position seems a bit daunting.

Here I think the answer is ...

Keep a variable, say last_scroll_position, and when you have a scroll, if last_scroll_position - current_position> 0, user scrolls , And if below 0 is less than then

I recommend that you check this example:

behaves strangely in Faxx, it is removed several times due to smoothness scrolling, but it works, here are an example:

  // scroll The status creates an element to print $ ("& lt; p id = 'test' & gt;"). Adendo ("body"). CSS ({Padding: "5px 7px", background: "# e9e9e9", status: "fixed", bottom: "35px", left: "35px"}); // "scroll" event $ (window) .scroll (function (e) {var target = e.currentTarget, scrollTop = target.scrollTop || window.pageY offset, scrollHait = target.soproHight || document.body.scrollHeight (ScrollTop & gt; lastScrollTop) {scrollText = "& lt; b & gt; Scroll down & lt; / b & gt;";} and {scrollText}, last circle top = $ (target). "Last Secretall"). 0, Scroll Text = ""; = "& lt; b & gt; Scroll Up & lt; / b & gt;"} $ ("# Exam"). Html (Scroll-Test + "& Lt; br & gt; Scrolltop:" + ScrollTop + "& lt; br & gt; Final Sklatop:" + Previous The scrollttop;); scrollHyight - scrollTop === $ (target). WinnerHeight ()) {console.log ("► End of scrolls");} prevents current scrolltable $ (target) data (" Ultimate Skaltop ", Scrolltop);});  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -