jQuery判断元素离页面顶部的高度

    <script language="javascript" type="text/javascript">  

       jQuery(document).ready(function () { //     

    $(window).height() //    

    alert($("#linkmsg").height()); //

        alert($(document).scrollTop()); // 

           jQuery(window).scroll(function () { //       

         var scrolltop = $(document).scrollTop(); //    

            if (scrolltop >= $(document).height() -$("#linkmsg").height()) { //      

              $("#div1").hide(); //           

     }

else { //      

              $("#div1").show(); //       

         } //         

   });  

jQuery(window).scroll(function () {              

   var st = document.documentElement.scrollTop;//滚去的高度   

              var ch = document.documentElement.clientHeight;//窗口的高度       

          var at = document.getElementById("linkmsg").offsetTop;//元素离页面顶部的高度 alert(st); alert(ch); alert(at);

//     

       

                var v = ch - (at - st);//元素离窗口底部的高度,为负的话表示元素还在窗口底部下面      

                        if(v>=0){       

           alert(v);           

       alert("11");      

             $("#div1").hide();    

            }

else{       

          alert(v);  

               $("#div1").show();    

            }             

      });   

      });  

   </script>

posted @ 2015-11-02 09:29  Pavilion  阅读(2220)  评论(0编辑  收藏  举报