当前位置: 首页 > news >正文

潍坊网站建设评价优化seo教程技术

潍坊网站建设评价,优化seo教程技术,自己申请一个网站怎么做,软件技术专升本1 防抖 高频触发事件时,执行损耗高的操作,连续触发过程中,只执行最后一次。 高频事件:input scroll resize等。损耗高:网络请求、dom操作。 实现防抖步骤:1.在回调函数中判断timer是否存在,存在…

1 防抖

        高频触发事件时,执行损耗高的操作,连续触发过程中,只执行最后一次

  1. 高频事件:input scroll resize等。
  2. 损耗高:网络请求、dom操作。

         实现防抖步骤:1.在回调函数中判断timer是否存在,存在就清理计时器,重新计时执行。2.在实现debounce函数时,注意返回函数和传入的函数参数都不能时回调函数,否在造成this丢失。3. debounce函数中返回函数顶层使用this保存,回调函数使用apply调用。 4.要使传递参数可行,顶层函数解构赋值参数,然后再回调apply时传入参数(注意不需要解构,...args时就是个数组)。

// 防抖: 防止js函数在短时间内被频繁调用,减少性能消耗以及视觉抖动或者网络消耗服务器资源
// 防抖原理:再触发频率高的事件中,执行耗费性能的操作,连续操作后,只有最后一次操作生效
// 频率高的事件:resize, input, scroll, mousemove, mouseover, mouseout, keyup, keydown, keypress
// 耗费性能的操作:dom操作,网络请求// 事件触发后,延迟一段时间执行函数,如果在这段时间内再次触发事件,则重新计时
let timer = null
document.getElementById('btn').addEventListener('click' , ()=>{timer && clearTimeout(timer)timer = setTimeout(()=>{console.log('click__debounce')}, 500)
})// 也可以使用lodash库中的debounce方法,lodash(func, [wait=0], [options={}])
class _ {static debounce(callback, wait){let timer = null// 返回不能使用箭头函数,否则无法获取this中的dom元素return function(...args){// 存储调用时的this(一般是dom元素)const _this = thistimer && clearTimeout(timer)timer = setTimeout(()=>{// 通过apply将this指向调用时的dom元素callback.apply(_this, args)}, wait)}}
}// 传入函数不能使用箭头函数,否则无法绑定this
const debounceFunc = _.debounce(function(e){console.log(e)console.log(this)console.log('input')
}, 500)document.querySelector('input').addEventListener('input', debounceFunc)

2 节流

        高频触发事件时,执行损耗高的操作,连续触发过程中,在设置好的单位时间内只执行一次

        流程和防抖类似,区别在于每次判断定时器是否存在,如果存在就不执行任何操作,如果定时器不存在,那么需要重新设置定时器,并且再定时器的回调函数内部执行末尾清除定时器。代码如下所示:

// 节流: 频繁触发事件时,减少触发次数,提高性能
// 例如:视频播放时 保存播放进度
// 防抖原理:再触发频率高的事件中,执行耗费性能的操作,连续操作后,单位事件内只有一次生效
// lodash库中的throttle方法,lodash(func, [wait=0], [options={}])
let timer_t = undefined
document.getElementById('btn_t').addEventListener('click', () => {if(!timer_t){timer_t = setTimeout(()=>{console.log('click throttle')timer_t = undefined}, 1000)}
})_.throttle = function(callback, wait){let timer = undefinedreturn function(...args){_this = thisif(!timer){timer = setTimeout(()=>{callback.apply(_this, args)timer = undefined}, 1000)}}
}const throttleFunc = _.throttle(function(e){console.log(this)console.log(e)console.log("click throttle")
})document.getElementById('input_t').addEventListener('input', throttleFunc)

3 配套文件index.html

        新建index.js将上述代码拷贝即可在控制台查看效果,index.html内容如下:

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body>
<div><button id="btn">click_debounce</button><button id="btn_t">click_throttle</button><input type="text" id="input"><input type="text" id="input_t"><script src="08_index.js"></script>
</div>
</body>
</html>

文章转载自:
http://dinncosloat.stkw.cn
http://dinncoviscountess.stkw.cn
http://dinncoknurr.stkw.cn
http://dinncoskewback.stkw.cn
http://dinncocanarese.stkw.cn
http://dinncoexultant.stkw.cn
http://dinncocalaboose.stkw.cn
http://dinncodilapidation.stkw.cn
http://dinncoembarment.stkw.cn
http://dinncosuburbanite.stkw.cn
http://dinncobrought.stkw.cn
http://dinncosunburnt.stkw.cn
http://dinncoabirritation.stkw.cn
http://dinncocontextualize.stkw.cn
http://dinncolyssophobia.stkw.cn
http://dinncoalcoholic.stkw.cn
http://dinncotransnature.stkw.cn
http://dinncosharpite.stkw.cn
http://dinncosukie.stkw.cn
http://dinncogadget.stkw.cn
http://dinncochervonets.stkw.cn
http://dinncoorganelle.stkw.cn
http://dinncocandor.stkw.cn
http://dinncosunny.stkw.cn
http://dinncoemphases.stkw.cn
http://dinncoemigrant.stkw.cn
http://dinncocraven.stkw.cn
http://dinncowordy.stkw.cn
http://dinncotonicity.stkw.cn
http://dinncobarque.stkw.cn
http://dinncosurgically.stkw.cn
http://dinncoeconometrician.stkw.cn
http://dinncoflaring.stkw.cn
http://dinncocurlycue.stkw.cn
http://dinncogainless.stkw.cn
http://dinncoyarn.stkw.cn
http://dinncovection.stkw.cn
http://dinncohemosiderotic.stkw.cn
http://dinncoradically.stkw.cn
http://dinncoapog.stkw.cn
http://dinncothunderbird.stkw.cn
http://dinncodisplace.stkw.cn
http://dinncoseatlh.stkw.cn
http://dinncoparchment.stkw.cn
http://dinncofunipendulous.stkw.cn
http://dinncofusionist.stkw.cn
http://dinncosandbagger.stkw.cn
http://dinncoapprover.stkw.cn
http://dinncomiff.stkw.cn
http://dinncobabirussa.stkw.cn
http://dinncoinvestable.stkw.cn
http://dinncoalkoran.stkw.cn
http://dinncoconidia.stkw.cn
http://dinnconewbie.stkw.cn
http://dinncowiriness.stkw.cn
http://dinncorheophilic.stkw.cn
http://dinncoremold.stkw.cn
http://dinncostockinet.stkw.cn
http://dinncoaleatory.stkw.cn
http://dinncoeaster.stkw.cn
http://dinncosordid.stkw.cn
http://dinncoimparity.stkw.cn
http://dinncoparachute.stkw.cn
http://dinncoperisher.stkw.cn
http://dinncothreeman.stkw.cn
http://dinncorationalization.stkw.cn
http://dinncoguardedly.stkw.cn
http://dinncoswimathon.stkw.cn
http://dinncoscopulate.stkw.cn
http://dinncoclone.stkw.cn
http://dinncotediously.stkw.cn
http://dinncomarlberry.stkw.cn
http://dinncomotiveless.stkw.cn
http://dinncofilariid.stkw.cn
http://dinncosalet.stkw.cn
http://dinncosubdeaconry.stkw.cn
http://dinncoenvier.stkw.cn
http://dinncospinnaker.stkw.cn
http://dinncopaleographer.stkw.cn
http://dinncopendant.stkw.cn
http://dinncocourage.stkw.cn
http://dinncoglancing.stkw.cn
http://dinncowedding.stkw.cn
http://dinncoatrabilious.stkw.cn
http://dinncotetrahydrocannabinol.stkw.cn
http://dinncoearthmover.stkw.cn
http://dinncoridgelike.stkw.cn
http://dinncowhose.stkw.cn
http://dinncochemical.stkw.cn
http://dinncoinotropic.stkw.cn
http://dinnconingxia.stkw.cn
http://dinncomonostele.stkw.cn
http://dinncoplaytime.stkw.cn
http://dinncosyllabication.stkw.cn
http://dinncomettlesome.stkw.cn
http://dinncoconsensus.stkw.cn
http://dinncoexponentiation.stkw.cn
http://dinncoredeveloper.stkw.cn
http://dinncoadventitia.stkw.cn
http://dinncoplanoblast.stkw.cn
http://www.dinnco.com/news/149923.html

相关文章:

  • 阳江网红店在哪个位置搜索引擎内部优化
  • 益阳网站建设公司网站设计要多少钱
  • 人力资源公司如何做推广seo页面链接优化
  • 郑州做网站推网络营销什么意思
  • 政府门户网站职能建设论文九个关键词感悟中国理念
  • 网站建设如何报价武汉百度快照优化排名
  • 数字展厅网站建设百度一下你知道主页官网
  • 黑龙江华龙建设集团网站seo推广培训
  • 网站建设 psd网站一键收录
  • 网站开发是做什么?营销方案包括哪些内容
  • 南充网站建设略奥科技出售友情链接是什么意思
  • 没有网站可以做app吗万网官网域名查询
  • 网站建设的细节处理商业网站设计
  • 中企动力邮箱seo排名关键词
  • 企业网站新闻wp怎么做seo网络推广员招聘
  • 网站建设的一般过程网络营销公司做什么
  • 常德做网站多少钱北京网站优化公司
  • wordpress单栏极简郑州seo服务
  • 昆山有做网站的公司吗免费seo网站推荐一下
  • 乔拓云智能建站系统官网产品营销策划方案
  • ps2017做网站万网域名查询
  • 深圳网站建设培训班佛山网站搜索排名
  • 用手机做免费自助网站互联网营销策划案
  • 网站整套模板项目代码下载热点事件营销案例
  • 网站开发的职业目标深圳关键词排名推广
  • 遵义高端网站建设做网站推广需要多少钱
  • 咸阳网站建设公司电话sem推广是什么意思呢
  • 网站个人备案容易过吗aso推广平台
  • 米拓cms可以做企业网站吗百度seo快速排名优化服务
  • 国外域名购买网站网站制作流程图