企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
[toc] ## hash与id ![](https://box.kancloud.cn/79d2ebb0ec0b72c6cac0f8196844d386_382x480.png) ## tween ``` npm i tween.js ``` ``` import TWEEN from 'tween.js'; ``` ``` beforeRouterUpdate(to,from,next){ this.animate(to); next(); } ,methods:{ animate(to){ function animateFunc(time){ requestAnimationFrame(animateFunc) TWEEN.update(time); } if(to.hash){ //默认是带#,要去掉 var el = document.getElementById(to.hash.slice(1)); var doc = document.getElementByClassName('doc')[0]; if(el){ animateFunc(); new TWEEN.Tween({ number:doc.scrollTop; }).to({ number:el.offsetTop; },500).onUpdate(function(){ //这个this应该是new Tween的实例 doc.scrollTop = this.number.toFixed(0) }).start() } } } ,beforeRouterEnter(to,from,next){ next((vm)=>{ vm.animate(to); }) } } ```