zoukankan      html  css  js  c++  java
  • 移动端滚动条滚动收集

    1.锚点链接

    2.document.getElementById(rewardid).scrollIntoView(); 

    3.

    Math.easeout = function (A, B, rate, callback) {
        if (A == B || typeof A != 'number') {
            return;    
        }
        B = B || 0;
        rate = rate || 2;
        
        var step = function () {
            A = A + (B - A) / rate;
            
            if (A < 1) {
                callback(B, true);
                return;
            }
            callback(A, false);
            requestAnimationFrame(step);    
        };
        step();
    };
    var doc = document.body.scrollTop? document.body : document.documentElement;
    Math.easeout(doc.scrollTop, 0, 4, function (value) {
        doc.scrollTop = value;
    });

     页面滚动到指定位置:

    const rewardid = getUrlParameter('reward_id');
                             const rewardEle = document.getElementById(rewardid); 
                                if(rewardid && rewardEle){
                                  let re = rewardEle.getBoundingClientRect();
                                  this.scrollSmoothTo(re.top - 150);
                                } 
    
    -----------------------------------------------------
    
    
    scrollSmoothTo(position) {
                    if (!window.requestAnimationFrame) {
                            window.requestAnimationFrame = function(callback, element) {
                                return setTimeout(callback, 17);
                        };
                    }
                    // 当前滚动高度
                    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    // 滚动step方法
                    var step = function () {
                        // 距离目标滚动距离
                        var distance = position - scrollTop;
                        // 目标滚动位置
                        scrollTop = scrollTop + distance / 5;
                        if (Math.abs(distance) < 1) {
                            window.scrollTo(0, position);
                        } else {
                            window.scrollTo(0, scrollTop);
                            requestAnimationFrame(step);
                        }
                    };
                    step();
                }
  • 相关阅读:
    第三章 SpringCloud之Eureka-Client服务提供者
    第二章 SpringCloud之Eureka-Server服务发现组件
    第一章 SpringCloud简介
    Storm之WordCount初探
    Solr之java实现增删查操作
    Solr安装并导入mysql数据
    java之消息队列ActiveMQ实践
    Ant Design使用方法
    Reactjs之实现js跳转路由
    React之js实现跳转路由
  • 原文地址:https://www.cnblogs.com/sybboy/p/12842914.html
Copyright © 2011-2022 走看看