animateMotion使用腳本控制

項目需求是機器人在辦公室移動了一段軌跡,需要將軌跡以動畫的形式展示出來。

首先使用了path畫軌跡,animateMotion做機器人移動。

問題:每次軌跡重繪或更新時,animateMotion移動的軌跡不對
解決方案:

  • html
 <rect x="-7" y="-7.5" width="14" height="15" fill="url(#robot_icon)" v-show="!stopAani" >
              <animateMotion :path="pathd" begin="0.5s" :dur="dur+'s'" v-if="pathd" repeatCount="indefinite" id="animate_motion" />  
            </rect>
  • js
document.getElementById("animate_motion").beginElement
path軌跡動畫
  • html
<path :d="pathd" class="bg_path trail_1"></path> 
  • js
let path = document.querySelector('.trail_1')
 let length = path.getTotalLength();    
 // 清除之前的動作
 path.style.transition = path.style.WebkitTransition = 'none';
 // 設(shè)置起始點
path.style.strokeDasharray =  length + ' ' + length;
path.style.strokeDashoffset = length;
// 獲取一個區(qū)域,獲取相關(guān)的樣式,讓瀏覽器尋找一個起始點。
path.getBoundingClientRect();
 // 定義動作
path.style.transition = path.style.WebkitTransition = `stroke-dashoffset ${this.dur}s linear`
 // Go!
path.style.strokeDashoffset = '0';  
補充

停止,啟動。機器人動畫

<svg id="svg_an">
        <defs>
          <pattern id="robot_icon" width="100%" height="100%" patternContentUnits="objectBoundingBox">
            <image width="1" height="1" xlink:href="static/images/robot/jqr.png"/>
          </pattern>  
        </defs> 

 <rect x="-7" y="-7.5" width="14" height="15" fill="url(#robot_icon)" v-show="!stopAani" >
              <animateMotion :path="pathd" begin="0.5s" :dur="dur+'s'" v-if="pathd" repeatCount="indefinite" id="animate_motion" />  
            </rect>

<svg>
var pause = document.getElementById('svg_an'); 
var unPause = document.getElementById('svg_an'); 

function parar(){ 
    pause.pauseAnimations(); 
} 
function voltar(){ 
    unPause.unpauseAnimations(); 
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 在前面一篇博客,介紹了 Selenium 的基本用法和爬蟲開發(fā)過程中經(jīng)常使用的一些小技巧,利用這些寫出一個瀏覽器爬...
    FifiZhuang閱讀 11,230評論 4 81
  • 網(wǎng)絡(luò)營銷名詞大全 二、數(shù)據(jù)分析 DA:(Digital Marketing Analytics)就是數(shù)字營銷分析。...
    專業(yè)摸魚閱讀 1,229評論 0 0
  • 實際工作中,SVG大多數(shù)是用 +<defs></defs>(或者symbol)+ + 的組合來使用的,defs ...
    風之化身呀閱讀 7,364評論 1 4
  • 第一部分 HTML&CSS整理答案 1. 什么是HTML5? 答:HTML5是最新的HTML標準。 注意:講述HT...
    kismetajun閱讀 28,884評論 1 45
  • 引用CSS方式 內(nèi)部引用 html文件中寫一個 標簽,并將樣式寫入到里面,舉例: 外部引用 通過 標簽實現(xiàn),里面有...
    dawsonenjoy閱讀 593評論 0 0

友情鏈接更多精彩內(nèi)容