探究 butterfly 框架中的插件

164639_P5XI_2287563.jpg

164639_yFNv_2287563.png

 


在 /butterfly/js/butterfly-amd.js 中列明了butterfly框架有什么插件















这里介绍一下加载了的非常有用的小插件:spin.js 和 moment.js。

首先介绍一下 spin.js 这是一个 loading 动画(菊花图)的小插件,在加载等待的时候经常用到。特别是 ajax 请求 success 前的 loading 过程。

如果不在 butterfly 中使用,官方文档已经有很详细的说明 spin.js 。这里主要谈一谈在 butterfly 框架中的使用。

define(['butterfly/view', 'spin'], function(View, Spin){      //在 butterfly 中引入 spin.js 
  return View.extend({

    render: function(){
      console.log('exhibition/index.html render');
    },
    onShow: function(){
      console.log('exhibition/index.html onShow');
      this.showLoadingPage();
    },
    showLoadingPage: function () {
        var opts = {                                    //对 spin 样式进行设置
          lines: 12, // The number of lines to draw
          length: 7, // The length of each line
          width: 5, // The line thickness
          radius: 10, // The radius of the inner circle
	  corners: 1, // Corner roundness (0..1)
	  rotate: 0, // The rotation offset
	  direction: 1, // 1: clockwise, -1: counterclockwise
	  color: '#000', // #rgb or #rrggbb or array of colors
	  speed: 1, // Rounds per second
	  trail: 100, // Afterglow percentage
	  shadow: true, // Whether to render a shadow
	  hwaccel: false, // Whether to use hardware acceleration
	  className: 'spinner', // The CSS class to assign to the spinner
	  zIndex: 2e9, // The z-index (defaults to 2000000000)
	  top: '50%', // Top position relative to parent
	  left: '50%' // Left position relative to parent
      };

      this.spinner = new Spin(opts);    
      var target = $("#foo").get(0);    //这里很特别,不知道是不是 butterfly 的问题,一定要带上.get()来
      this.spinner.spin(target);        //选择元素,测试过用 $('.foo') 和 $('#foo') 都会把这个元素删除
  },
  });
});

至此,可爱的菊花图就出现了!!!173944_OY8L_2287563.png

如何实际地用在 ajax 中? 请慢慢品味亮哥发给大家的 client.js 。

Ps: 在 spin.js 上可以在线设置样式,很好玩。

write by xylitol_lin

转载于:https://my.oschina.net/u/2287563/blog/358151

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值