The page scrolls to a location to navigate the display and execute the function

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)

}

what result do you expect? What is the error message actually seen?

Jan.08,2022

stop the timer every time you come in


setInterval replace it with setTimeout


it is equivalent to re-registering a setInterval event every time a scrolling event is triggered. You don't quite understand why you need to add 200ms Interval to the scrolling event of throttling 800ms

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4c10d-273c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4c10d-273c0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?