Can I detect the user viewable area on the browser?

前端 未结 4 1512
情话喂你
情话喂你 2020-12-07 18:53

As you can see the image below, there is \"A\", \"B\", \"C\", \"D\" and \"E\" on the website, and the user may only can see the A, B, and a little parts of D in their browse

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 19:30

    You can get window's visible area by,

    var pwidth = $(window).width();
    var pheight = $(window).height();
    

    Then get document scroll,

    $(document).scroll(function(e) {
           var top = $(this).scrollTop();       
           $("h1").html("total visible area is from:"+ top +" to "+ (pheight + top) +"px");
        });
    

    Full example is here : http://jsfiddle.net/parag1111/kSaNp/

提交回复
热议问题