<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script> <script> $(function(){ $(window).scroll(function() { var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(this).height(); if(scrollTop == 0){ alert('顶部'); } if(scrollTop + windowHeight == scrollHeight ){ alert('底部'); } }) }) </script> </head> <body style="height: 1000px;"> </body> </html>