![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js相关
宝贝莫慌~~
前端开发工程师一枚
展开
-
setTimeout用法——避免重复性触发操作
btn的click事件,每次点击都会执行给定的function,如果function复杂的话,很容易消耗内存解决方法——setTimeout延时处理。给function做延迟处理,比如600毫秒后执行,如果在600毫秒内再次触发方法,则将之前的timeout清除。关键代码: let isr = false let timer = null let oBtn = document.getElementById('oBtn') oBtn.onclick = function ()原创 2020-10-30 16:11:23 · 2455 阅读 · 0 评论 -
干货代码——Div拖拽功能
拖拽功能需要用到的三个方法:onmousedown,onmousemove,onmouseup鼠标按下时(onmousedown): 记录下div拖拽前鼠标的位置鼠标移动时(onmousemove):动态计算元素的位置(left, top)鼠标抬起时(onmouseup):释放掉上边两个事件<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title&原创 2020-10-29 17:26:42 · 221 阅读 · 0 评论