problem description
the requirement is that the page scrolls to a certain location and the side navigation displays and executes a function that performs dom operations based on time. Now the problem is that when the function executes, scrolling the pulley speeds up the time. Every dom operation speeds up
.the environmental background of the problems and what methods you have tried
at first I thought it had something to do with the throttling function, but there was still a problem after trying
related codes
/ / window.onscroll = throttle (function () {
let scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
if(scrollTop >= 360){
inter = setInterval("fun()",200);
$("-sharprightnav").fadeIn(500);
}else{
$("-sharprightnav").fadeOut(500);
}
}, 800)
var t = 10.2;
function fun () {
if (t >-1) {br > console.log (t)
if (t > = 10.01) {
$(".contact").addClass("black");
} else if (t > = 9.81) {
$(".contact").removeClass("black");
$(".contact").addClass("white");
} else if (t > = 9.61) {
$(".contact").removeClass("white");
$(".contact").addClass("black");
}
else if (t > = 9.41) {
$(".contact").removeClass("black");
$(".contact").addClass("white");
} else if (t > = 9.21) {
$(".contact").removeClass("white");
$(".contact").addClass("black");
}
else if (t > = 9.01) {
$(".contact").removeClass("black");
$(".contact").addClass("white");
}
else if (t > = 8.81) {
$(".contact").removeClass("white");
$(".contact").addClass("smile1");
} else if (t > = 8.61) {
$(".contact").removeClass("smile1");
$(".contact").addClass("smile2");
$(".contact span").css("display","block");
$(".contact-duihua").css("display","block")
} else if (t > = 8.41) {
var index=0;
var word=" Click here";
function type () {
document.getElementById ("clickthis"). InnerText = word.substring;
}
setInterval (type, 50);
} else if (t > = 8.21) {
var index=0;
var word=" We"ll contact you right away";
function type1 () {
document.getElementById ("ournow"). InnerText = word.substring (0indexPP);
}
setInterval (type1, 50);
} else if (t > = 0.61) {
// console.log("")
$(".contact span").css("display","block");
} else if (t > = 0.41) {
$(".contact").removeClass("smile2");
$(".contact").addClass("smile1");
} else if (t > = 0.21) {
$(".contact-duihua").hide(200);
$(".contact span").hide(200);
} else if (t < = 0) {
clearInterval(inter);
// console.log("da"+t)
}