Phantom0174
Phantom0174
近期写了个类似的替代性专案,从基本上舍弃了爆搜,改用chunks与draw buffer解决掉大部分的效能瓶颈。 目前还不是很完整,但核心代码写好了。 https://github.com/phantom0174/canvas-nice.js
You can try with my newly-developed module, which solves this issue by implementing chunks and drawing buffer. https://github.com/phantom0174/canvas-nice.js Hope this helps.
就我个人对代码的理解,this.on... = window.on... 是在把原本 window 对滑鼠移动的监听函数暂存起来,下面对window.on... 是先用自订的函数覆盖过去。 而之所以要呼叫 this.on... && this.on...(e) 是类似 class 中呼叫 super() 的概念,也就是呼叫原本 window 对滑鼠的监听函数。 整句的意思是:如果原本有 window 对滑鼠的监听函数,则在执行自定义动作后呼叫原函数。 最后在下方的 destroy() 函数中才再利用赋值将 window 原有的监听函数还回去。 希望有帮上忙。
我在这个优化版本的套件中把这个功能实作出来了 可自订大小范围 https://github.com/phantom0174/canvas-nice.js