代码之家  ›  专栏  ›  技术社区  ›  Ace

离子型GSAP DrawSVGPlugin

  •  0
  • Ace  · 技术社区  · 8 年前

    我想在Ionic3中实现这个插件。据我所知,npm包没有来自club的插件,也没有@types/gsap。我添加了DrawSVGPlugin。js进入node\u模块/gsap,然后重新创建了一个android平台。 在里面ts文件作为我尝试的导入:

    import { DrawSVGPlugin } from "gsap/DrawSVGPlugin";
    

    作为调用插件:

    TweenLite.to("#svg_1", 1, {drawSVG:"40% 60%", ease:Power1.easeInOut});
    

    我的svg html源:

    <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" viewBox="0 0 100 100" preserveAspectRatio="none">
      <line stroke-linecap="undefined" stroke-linejoin="undefined" id="svg_1" y2="45.78805" x2="87.36405" y1="45.24458" x1="8.28813" stroke-width="12.5" stroke="#000" fill="none"/>
    </svg>
    

    有人能告诉我我做错了什么吗?还是有不同的方法?

    1 回复  |  直到 8 年前
        1
  •  0
  •   Pablo E. Lujambio    8 年前

    在Ionic中使用DrawSVG时(我已经在几个项目上复制并测试了此方法):

    1. 将要使用的GSAP文件放在下面 src/assets/javascripts ,并调用脚本文件,就像在 index.html :

      <script src="assets/javascripts/gsap/TweenLite.min.js"></script>
      <script src="assets/javascripts/gsap/plugins/DrawSVGPlugin.min.js"></script>
      
    2. 添加您将要使用的GSAP变量

      /*
        Normal imports here..
      */
      import { LoginPage } from "../login/login";
      
      declare var TimelineLite: any;        
      declare var TweenLite: any;
      declare var Power1: any;
      
      @Component({
        selector: 'page-profile',
        templateUrl: 'profile.html',
        providers: [Data, Api, DatePipe]
      })
      
      export class ProfilePage {
      ...
      
    3. 像平常一样使用。正如您已经知道的,SVG必须是内联的。

      TweenLite.to("#svg_1", 1, {drawSVG:"40% 60%", ease:Power1.easeInOut});