国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

MIP文檔手冊(cè) / 動(dòng)畫

動(dòng)畫

Naboo 是一個(gè)前端動(dòng)畫解決方案,包含動(dòng)畫調(diào)度機(jī)制和動(dòng)畫工具集,支持串并行動(dòng)畫及回調(diào),支持自定義插件;

1. 聲明

可以在類和實(shí)例中根據(jù)場景進(jìn)行挑選使用

var util = require('util');

// 類對(duì)象
var Naboo = util.naboo;

// 實(shí)例對(duì)象
var naboo = new util.naboo();
naboo.animate(...);

2. 使用

1) naboo.animate(dom, prop, opt)

  • 描述:animate插件,專門用于進(jìn)行動(dòng)畫操作的插件

  • 參數(shù)列表:

參數(shù)類型必選描述
domObject需要進(jìn)行動(dòng)畫的dom元素
propObject需要進(jìn)行動(dòng)畫π的css屬性鍵值對(duì)對(duì)象
optObject可選的動(dòng)畫參數(shù)對(duì)象
opt.durationnumber動(dòng)畫時(shí)長,默認(rèn)值400,單位ms
opt.easestring動(dòng)畫的緩動(dòng)函數(shù)名,默認(rèn)值ease,可選值包括ease、linear、ease-in、ease-out、ease-in-out
opt.delaynumber動(dòng)畫延遲執(zhí)行的時(shí)間,默認(rèn)值0,單位ms
opt.cbFunction動(dòng)畫完成后的回調(diào)函數(shù)
opt.modestring動(dòng)畫的模式,默認(rèn)值transition,可選值包括transition、keyframes(暫未支持)、js(暫未支持)
  • 代碼示例
      naboo.animate(dom, {
          'transform': 'translateX(200px)'
      }, {
          duration: 2000,
          ease: 'ease',
          delay: 1000,
          mode: 'transition',
          cb: function() {
              console.log(1);
          }
      }).start();

2) naboo.start(fn)

  • 描述:開始執(zhí)行動(dòng)畫的指令函數(shù)

  • 參數(shù)列表:

參數(shù)類型必選描述
fnFunction動(dòng)畫完成后的回調(diào)函數(shù)
  • 使用示例:

      naboo.animate(dom, {      'transform': 'translateX(200px)'
      }, {
          duration: 2000
      }).start();

3) naboo.next()

  • 描述:讓動(dòng)畫進(jìn)入下一步的指令函數(shù),在調(diào)用 done 或者 register(注冊(cè)插件)方法需要調(diào)用 next() 才能進(jìn)入下一個(gè)動(dòng)畫;

  • 參數(shù)列表:無

  • 使用示例:

      naboo.animate(dom, {      'transform': 'translateX(200px)'
      }, {
          duration: 2000
      }).done(function(next) {
          console.log(1);
          next();
      });

4) naboo.cancel()

  • 描述:取消動(dòng)畫的指令,調(diào)用該函數(shù)后,當(dāng)前未執(zhí)行完的動(dòng)畫仍會(huì)繼續(xù)執(zhí)行完成,后續(xù)的動(dòng)畫不會(huì)執(zhí)行

  • 參數(shù)列表:無

  • 使用示例:

      var instance;
      btnStart.onclick = function () {
          instance = naboo.animate(dom, {
              'transform': 'translateX(200px)'
          }, {
              duration: 2000,
              cb: function() {
                  console.log(1);
              }
          }).start();
      }
      btnCancel.onclick = function () {
          instance.cancel();
      }

5) naboo.on(name, fn)

  • 描述:事件綁定,可以通過該函數(shù)綁定自定義事件

  • 參數(shù)列表:

參數(shù)類型必選描述
namestring事件名
fnFunction事件觸發(fā)的方法
  • 使用示例:

      var handle = function(event) {
          console.log(event);
      }
      btn.onclick = function () {
          naboo.on("customer", handle);
      }

6) naboo.off(name, fn)

  • 描述:解除事件綁定

  • 參數(shù)列表:

參數(shù)類型必選描述
namestring事件名,如果為空則解除所有事件
fnFunction事件觸發(fā)的方法,如果為空則解除該name下所有事件
  • 使用示例:

      var handle = function(event) {
          console.log(event);
      }
      btn.onclick = function () {
          console.log('解除事件');
          naboo.off("customer", handle);
      }

7) naboo.trigger(name, data)

  • 描述:觸發(fā)事件

  • 參數(shù)列表:

參數(shù)類型必選描述
namestring事件名,如果為空則解除所有事件
dataObject觸發(fā)事件時(shí)需要傳遞的數(shù)據(jù)
  • 使用示例:

      btn.onclick = function () {
          naboo.trigger("customer", {
              a: 1
          });
      }

    8) naboo.p(list)

  • 描述:Naboo的并行插件,通過該方式可以將多個(gè)動(dòng)畫并發(fā)執(zhí)行,可以通過類或?qū)嵗龑?duì)象進(jìn)行調(diào)用

  • 參數(shù)列表:

參數(shù)類型必選描述
listarray需要并行的naboo對(duì)象列表
  • 使用示例:

      naboo.p(
          naboo.animate(dom1, {
              'transform': 'translateX(200px)'
          }, {
              duration: 2000,
              cb: function() {
                  console.log(1);
              }
          }),
    
          naboo.animate(dom2, {
              'transform': 'translateX(200px)'
          }, {
              duration: 3000,
              cb: function() {
                  console.log(2);
              }
          })
      ).start();

8) naboo.done(fn)

  • 描述:Naboo的done插件,可用于在任何一個(gè)動(dòng)畫插件后進(jìn)行回調(diào),可以通過類或?qū)嵗龑?duì)象進(jìn)行調(diào)用;

  • 注意:需要在該方法中調(diào)用 next() 才能進(jìn)入下一步的動(dòng)畫,因?yàn)榭紤]到可能會(huì)有一些異步行為,如 ajax 請(qǐng)求

  • 參數(shù)列表:

參數(shù)類型必選描述
fnfunction回調(diào)函數(shù)
  • 使用示例:

      naboo.animate(dom1, {
          'transform': 'translateX(200px)'
          }, {
              duration: 2000,
              cb: function() {
                  console.log(1);
              }
          }).done(function(next) {
              console.log(2);
              next();
          }).animate(dom2, {
              'transform': 'translateX(200px)'
          }, {
              duration: 2000,
              ease: "ease",
              cb: function() {
                  console.log(3);
              }
      }).start();

P.S.: 示例代碼標(biāo)識(shí)在dom1的動(dòng)畫執(zhí)行完成后再執(zhí)行dom2的動(dòng)畫

3. 類的靜態(tài)方法:Naboo.register(name, fn)

  • 描述:插件注冊(cè)函數(shù),如果animate不能滿足需求,亦或是站長需要封裝自己的插件來做到方便調(diào)用,可以通過該方式來進(jìn)行方法注冊(cè);

  • 注意:在實(shí)現(xiàn)register fn時(shí)需調(diào)用next()才能執(zhí)行下一個(gè)動(dòng)畫;

  • 參數(shù)列表:

參數(shù)類型必選描述
fnfunction插件函數(shù),用于定義插件的執(zhí)行邏輯
  • 使用示例:

       Naboo.register('animate', function (next, dom, prop, opt) {
          opt = opt || {};
          var cb = opt.cb;
          opt.cb = function () {
              cb && cb();
              next();
          };
          opt.mode = ([
              'transition'
          ].indexOf(opt.mode) > -1) ? opt.mode : 'transition';
          Naboo[opt.mode](dom, prop, opt);
      });