animateMotion使用腳本控制

項(xiàng)目需求是機(jī)器人在辦公室移動(dòng)了一段軌跡,需要將軌跡以動(dòng)畫的形式展示出來。

首先使用了path畫軌跡,animateMotion做機(jī)器人移動(dòng)。

問題:每次軌跡重繪或更新時(shí),animateMotion移動(dòng)的軌跡不對
解決方案:

  • 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軌跡動(dòng)畫
  • html
<path :d="pathd" class="bg_path trail_1"></path> 
  • js
let path = document.querySelector('.trail_1')
 let length = path.getTotalLength();    
 // 清除之前的動(dòng)作
 path.style.transition = path.style.WebkitTransition = 'none';
 // 設(shè)置起始點(diǎn)
path.style.strokeDasharray =  length + ' ' + length;
path.style.strokeDashoffset = length;
// 獲取一個(gè)區(qū)域,獲取相關(guān)的樣式,讓瀏覽器尋找一個(gè)起始點(diǎn)。
path.getBoundingClientRect();
 // 定義動(dòng)作
path.style.transition = path.style.WebkitTransition = `stroke-dashoffset ${this.dur}s linear`
 // Go!
path.style.strokeDashoffset = '0';  
補(bǔ)充

停止,啟動(dòng)。機(jī)器人動(dòng)畫

<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輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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

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