How to use the scroll bar to monitor events in jquery

jquery uses the scroll bar to monitor events: 1. Use [$(window).scrollTop():] to get the height of the vertical scroll bar from the document head; 2. Use [$(document).scrollLeft()] to get the horizontal scroll The distance of the bar.



The operating environment of this tutorial: windows7 system, jquery 3.2.1 version, this method is applicable to all brand computers.

jQuery uses the scroll bar to monitor events:

Let’s take an example first:

1

2

3

4

5

6

7

8

9

10

11

12

$(document).ready(function(){//Execute

    $(window) after the document is loaded . scroll(function(){//Start monitoring the scroll bar

        //Get the current scroll bar height

        var topp = $(document).scrollTop();

        //Used to debug the pop-up current scroll bar height

        //alert(topp);

        // Determine if the scroll bar is greater than 90, "ok" pops up

        if(topp> 90){         //alert("ok");         }     })







))

Syntax

$(window).scrollTop();//Get the height of the vertical scroll bar from the document head

$(document).scrollLeft() //Get the distance of the horizontal scroll bar

$(document).height() // Get the height of the entire page

$(window).height() //Get the current, that is, the height of the part of the page that your browser can see. This size will change when you zoom the browser window size, which is the same as the document are different

Guess you like

Origin blog.csdn.net/ny18002122997/article/details/112552604