I have been wondering how to monitor the events of the scroll bar. Now I understand it.
The following code is the supervisorMove as long as you listen to the scroll bar, The lower returns the DIV display and hidden code at the top.
window.onscroll = function () { var t = document.documentElement.scrollTop || document.body.scrollTop; if (t > 0) { $(".cbbfixed").css("bottom", "10px"); } else { $(".cbbfixed").css("bottom", "-85px"); } }
Note: T: the distance from the scroll bar to the top
T> 0, that is, once the scroll bar is rolled, the IF () Statement is executed immediately. The code in else () is that when the scroll bar reaches the top, the DIV at the top is returned to hide
Return to the top button click operation
$("#cgotop").click(function(){ $('body,html').animate({ scrollTop: 0 }, 100); return false; });
Supplement:
1. Listen to the scroll bar event of an element
$ (Selector). Scroll (function (){.......});
2. Get the scroll distance of the scroll bar
$ (Selector). scrolltop (); $ (selector). scrolllefft ();
Scroll bar event