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(这是我的后续文章)

      

  • 相关阅读:
    Nginx 限流配置
    Nginx 跨域配置
    LVS实现负载均衡原理及安装配置详解
    Tomcat基本概念
    Hapoxy 基本配置概念
    rsync断点续传
    Nginx概念
    angular img标签使用err-src
    $ionicLoading自定义加载动画
    h5+jquery自制相机,获取图片并上传
  • 原文地址:https://www.cnblogs.com/jiangbanji/p/6025808.html
Copyright © 2011-2022 走看看