jQuery 顺序动画库 画布动画

  • 源码大小:1.69MB
  • 所需积分:1积分
  • 源码编号:19JP-3812
  • 浏览次数:1091次
  • 最后更新:2023年07月26日
  • 所属栏目:动画
我要下载
加入收藏
本站默认解压密码:19jp.com 或 19jp_com

简介

Canvas Animation是一个jQuery插件,它使用JavaScript和CSS样式将可控的连续动画应用于单个或多个元素。

如何使用它:

1.将jQuery库(slim build)和jQuery Canvas Animation插件的JavaScript&Stylesheet插入到html文件中。

<link href="jquery.canvas-animation.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" 
        integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" 
        crossorigin="anonymous"></script>
<script src="jquery.canvas-animation.min.js"></script>

2.创建一组要设置动画的元素。

<div id="canvas" class="demo">
  <div class="square red"></div>
  <div class="square green"></div>
  <div class="square blue"></div>
</div>

3.通过向元素添加CSS类和持续时间来创建循序渐进的动画,如下所示:

var myConf = {
    steps : [
      {
          addClass : 'ca-1',
          duration : 800
      },
      {
          addClass : 'ca-2',
          duration : 800
      },
      {
          addClass : 'ca-3',
          duration : 800
      },
      {
          addClass : 'ca-4',
          duration : 500
      }
    ]
};

4.将顺序动画应用于元素并完成。

$('#canvas').canvasAnimation(myConf);

5.用于自定义顺序动画的更多配置。

$('#canvas').canvasAnimation({

  // starts the animation after this timeout
  // 0 = starts immediately
  timeout: 0, 

  // reset duration in milliseconds
  resetDuration: 500, 

  // infinite loop
  infinity: true, 

  // enable autoplay
  autoplay : true,

  // enable controls
  controls: true,

  editor: {
    enable: false, // if true: show editor on page
    wrapper: '.jca-editor-container' // editor wrapper class
  },

  // use icons from an icon framework instead of css icons
  useIcons: false, 

  // icons
  icons: {
    backward: '<i class="fas fa-step-backward"></i>',
    play: '<i class="fas fa-play"></i>',
    pause: '<i class="fas fa-pause"></i>',
    stop: '<i class="fas fa-stop"></i>',
    forward: '<i class="fas fa-step-forward"></i>',
    expand: '<i class="fas fa-expand"></i>',
    editor: '<i class="fas fa-edit"></i>'
  },

  // class of controls wrapper
  controlsWrapper: '.controls', 

  // custom controls
  controlsTemplate:
  '<div class="controls">' +
      '<div class="backward #BACKWARD#"></div>' +
      '<div class="play #PLAY#"></div>' +
      '<div class="pause #PAUSE#"></div>' +
      '<div class="reset #RESET#"></div>' +
      '<div class="forward #FORWARD#"></div>' +
      '<div class="fullscreen #FULLSCREEN#"></div>' +
  '</div>',

  // class of step backward button
  backwardButton: '.backward', 
  
  // class of step forward button
  forwardButton: '.forward', 

  // class of play button
  playButton: '.play', 

  // class of pause button
  pauseButton: '.pause', 

  // class of reset button
  resetButton: '.reset', 

  // class of reset button
  stopButton: '.jca-stop', 

  // class of expand button
  expandButton: '.jca-expand', 

  // class of edit button
  editorButton: '.jca-editor',

  // class of goto button / add data-step="step-name"
  gotoButton: '.jca-goto',  

  // CSS class if the animation is done
  classDone: 'done', 

  // CSS class if the animation is paused
  classWait: 'wait',

  // CSS class if user clicked forward
  classForward: 'forward', 

  // CSS class if user clicked backward
  classBackward: 'backward', 

  // class of elements wrapper
  classWrap: 'canvas-animation',
  
});

7. Useful callback functions which will be fired when the animation starts or is paused/finished.

$('#canvas').canvasAnimation({

  // called before first animation step
  onPlay: null, 

  // called after last animation step
  onDone: null, 

  // called if classWait was added
  onWait: null  
  
});

更新日志:

v2.1.0 (2021-11-14)

  • Added gotoButton in options

v2.0.0 (2018-08-11)

  • Added width, height, top, left in px on editor.

2018-05-06

  • Fixed wrong css class in less and scss.
  • Changed config names.

2018-04-27

  • Added step forward / backward feature.

2018-04-22

  • Added "Pause instantly" feature.

预览截图