移动端滚动条滚动收集
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(); }