I use the following two methods to achieve the animation effect of imitating anchor point positioning. There is no problem in Zhuo system, but the positioning position in IOS is not accurate. Is there a compatibility problem?
related codes
//
function getElementTop(element){
var actualTop = element.offsetTop;
var current = element.offsetParent;
while (current !== null){
actualTop += current.offsetTop;
current = current.offsetParent;
}
return actualTop;
}
//
function scrollTo(y, duration) {
/*y:,duration:()*/
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
var distance = y - scrollTop;/*0,,0,*/
var scrollCount = Math.ceil(duration / 10);/*10,*/
var everyDistance = distance / scrollCount/**/
for (var index = 1; index <= scrollCount; indexPP){ /*scrollBy,duration,*/
setTimeout(function () { window.scrollBy(0, everyDistance) }, 10 * index);
}
}
look forward to God to help me see what happened. Thank you very much