Throttling function & Anti-shake function curry function

Source: Internet
Author: User

/*
Onscroll
OnResize
Input
。。。。。


Throttle function
Let high-frequency events reduce triggers into low-frequency events

var bstop = true;
Window.onscroll = function () {
if (!bstop) {
Return
}

Bstop = false;
SetTimeout (() =>{
var t = Document.documentElement.scrollTop | | Document.body.scrollTop;
Console.log (t);
Bstop = true;
},300)
}

function stabilization
When high frequency events are triggered, we do not need to know the process of frequent triggering, just need to know the final result
*/
var timer = null;
Window.onscroll = function () {
if (timer) {
Cleartimeout (timer);
}

Timer = SetTimeout (() =>{
var t = Document.documentElement.scrollTop | | Document.body.scrollTop;
Console.log (t);
},300)
}
</script>

/*
Lazy functions and the function of curry

*/

function GetStyle (obj,attr) {
if (Obj.currentstyle) {
return obj.currentstyle[attr]
}else{
Return getComputedStyle (Obj,false) [attr];
}
}


function GetStyle (obj,attr) {
if (Obj.currentstyle) {
GetStyle = function (obj,attr) {
return obj.currentstyle[attr];
}
}else{
GetStyle = function (obj,attr) {
Return getComputedStyle (Obj,false) [attr];
}
}
Return GetStyle (OBJ,ATTR);
}

Throttling function & Anti-shake function curry function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.