zoukankan      html  css  js  c++  java
  • js上拉跳转原理

      今天遇到一个需要上拉跳转的地方,其原理跟上拉加载有点类似,代码如下

    window.onscroll = function(){
       if(getScrollTop() + getClientHeight() == getTotalHeight()) {
            //执行跳转  ...对应你跳转的地址
            window.location.href = "...";
        }
    }        
    

      应用场景,移动端商品详情页面,通过上拉进入到图文详情。

      解释一下:

      getScrollTop():获取滚动条卷去高度;

      getClientHeight():获取可视区的高度;

      getTotalHeight():获取整个页面的整体高度,即滚动条的总长度。

      

    //获取滚动条当前的位置 
    function getScrollTop() {
    	var scrollTop = 0;
    	if(document.documentElement && document.documentElement.scrollTop) {
    		scrollTop = document.documentElement.scrollTop;
    	} else if(document.body) {
    		scrollTop = document.body.scrollTop;
    	}
    	return scrollTop;
    }
    
    //获取当前可视范围的高度 
    function getClientHeight() {
    	var clientHeight = 0;
    	if(document.body.clientHeight && document.documentElement.clientHeight) {
    		clientHeight = Math.min(document.body.clientHeight, document.documentElement.clientHeight);
    	} else {
    		clientHeight = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
    	}
    	return clientHeight;
    }
    
    //获取文档完整的高度 
    function getTotalHeight() {
    	return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
    }

      http://www.cnblogs.com/jiangbanji/p/6026755.html(这是我的后续文章)

      

  • 相关阅读:
    (转)R空间数据处理与可视化
    shell 脚本 exit 1 报错:numeric argument required问题解决
    如何在java中拟合正态分布
    Geometry关系高级操作
    IntelliJ IDEA 15.0.2远程debug tomcat
    jmc远程监控java服务
    Cannot assign requested address出现的原因及解决方案
    网络调试工具
    性能优化工具---sar
    性能优化工具---iostat
  • 原文地址:https://www.cnblogs.com/jiangbanji/p/6025808.html
Copyright © 2011-2022 走看看