for (var i = 0; i < leftMenuLi.length; i++) {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
leftMenuLi[i].onclick = function(i) {
return function() {
var duration = 500;
var interval = 100;
var distance = Math.abs(anchor[i] - scrollTop);
var step = distance / duration * interval;
var timer = setInterval(function() {
if (Math.abs(scrollTop - anchor[i]) < step) {
console.log("1-s->" + scrollTop);
console.log("2-a->" + anchor[i]);
document.documentElement.scrollTop = anchor[i];
document.body.scrollTop = anchor[i];
console.log("You are here");
window.clearInterval(timer);
console.log("doc"+document.body.scrollTop)
return;
} else if (anchor[i] > (scrollTop)) {
scrollTop += step
document.documentElement.scrollTop = scrollTop;
document.body.scrollTop = scrollTop;
} else if (anchor[i] < (scrollTop)) {
scrollTop -= step
document.documentElement.scrollTop = scrollTop;
document.body.scrollTop = scrollTop;
}
}, interval);
}
}(i);
}