再探 butterfly.js - 拋磚引玉篇(notification.js)

來源:互聯網
上載者:User

標籤:

再探 butterfly.js - 拋磚引玉篇(notification.js) 事情經過

今天又來研究butterfly.js的源碼(打醬油),發現了一個notification.js。顧名思義notification就是公告欄嘛,那麼這個notification.js到底有什麼用途呢?題外話:還有十幾天就過年… 我的新年願望是:準時出糧!

正片

先貼:

顯然,這真的是一個顯示狀態的公告欄。萬萬沒有想到butterfly.js會內建了這類外掛程式。那個這個notification.js到底要怎麼用呢?下面只貼出關鍵代碼,詳情請自行查閱notification.js。

defaults: {    duration: 2000,    autoDismiss: true,    type: ‘info‘,    showSpin: false},

這是notification.js的預設參數,又來顧名思義,duration是時間長度,autoDismiss是自動消失,type是類型,showSpin是顯示spin(菊花圖)。

initialize: function(options) {    _.extend(this, this.defaults, options);    this.el.classList.add(this.type);    this.el.innerHTML = options.message;    document.body.appendChild(this.el);    if (this.showSpin) this.spinner = new Spinner({        left: ‘20px‘,        lines: 7,        speed: 1.3,        length: 3,        radius: 3,        color: ‘#666‘    }).spin(this.el);},

initialize是用來初始化的function。_.extend()這是個承繼的function,new Spinner()是用來定義菊花圖。總的來說,這個initialize就是用來處理預設參數和自訂參數。原始碼就介紹到這裡,具體還是要自行查閱,原理和實現的方法都比較簡單。

用法

建立一個butterfly.js項目:

<input type="button" value="click" class="btn">
```javascriptevents:{    ‘click .btn‘:‘cl‘},cl:function(){    new Notification({        message: ‘我是info‘,        type: ‘info‘    }).show();}

點擊效果如下:

這個notification的樣式由butterfly.css內控制:

.notification {  position: fixed;  bottom: -40px;  -webkit-transition: bottom 1.25s;     -moz-transition: bottom 1.25s;          transition: bottom 1.25s;}.notification.active {  bottom: 0px;}

初始位置為bottom: -40px,添加.active後buttom: 0px。由於transition: bottom 1.25s;,會出現從下至上的出現效果。預設duration為2s,而且autoDismiss: true,所以在2s後公告欄會消失,移除.active。公告欄的位置由當前的0px,變為-40px。同理,因為有transition,會有一個從上至下的消失效果。

目前,notification.js提供4種type : well、info、warning、error。具體的操作,還請大家親自動手摺騰一下。

再探 butterfly.js - 拋磚引玉篇(notification.js)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.