material-refresh

Google Material Design swipe(pull) to refresh by using JavaScript and CSS3.

  • 所有者: lightningtgc/material-refresh
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Material Refresh

High Performance

Mobile only

Google Material Design swipe (pull) to refresh.

It uses CSS3 and JavaScript depend on Zepto or jQuery.

Actually, it's easy to convert the dependent js library or just use the vanilla JavaScript.

It's high performancenot which not impact the structure of sites.

Types and preview

Type1: Above surface (default)
Type2: Below surface
Type3: Button action

Demo

The Live Demo

Getting Started

Install it

Include material-refresh.min.js and material-refresh.min.css in your target html file.

<link rel='stylesheet' href='material-refresh.min.css'/>

<script src='material-refresh.min.js'></script>

Cause it is a plugin for Zepto or jQuery, so we also need to include Zepto or jQuery:

<script src='zepto.js'></script>

<!-- or include jQuery.js-->
<script src='jQuery.js'></script>

Usually, we will combine and compress all the css or js, depend on your needs.

You can also install it via Bower or npm:

bower install --save material-refresh
npm install --save material-refresh

Basic usage

Example for Type1: Above surface (default):

1.Instantiation:

mRefresh();

2.Finish the refresh and hide it:

mRefresh.resolve();

If you don't use this method, refesher will stop after the maxTime(Default: 6000ms).

Relations of three types

  • Type1 and Type2 can not use in the same time.
  • Type3 is depend on Type1 or Type2, cause it will determine the refresher position
  • Type3 and (Type1 or Type2) can use in the same time.

Advanced usage

Options

    // Default options 
     var opts = { 
         nav: '', //String, using for Type2 
         scrollEl: '', //String  
         onBegin: null, //Function 
         onEnd: null, //Function 
         top: '0px', //String 
         theme: 'mui-blue-theme', //String 
         index: 10001, //Number
         maxTime: 6000, //Number 
         freeze: false //Boolen 
     } 
    mRefresh(opts);

-- Using for turn into Type2, refresh body will below the nav surface

// Example
var opts = {
  nav: '#navMain'
}
scrollEl:

-- Custom scroll wrapper element, decide which elemnt will allow trigger refresh action.

-- Default:{ ios:document.body, android: document }

var opts = {
  scrollEl: '#mainWrapper'
}
onBegin: (Callback Function)

-- Trigger when the refresh body start to rotate because of the right gesture(swipe).

-- You can use this callback to pull ajax data or other action.

var opts = {
  onBegin: function(){
    alert('Begin to rotate');
    $.get('/whatevs.html', function(response){
        $('#someDom').append(response);
    });
  }
}
onEnd: (Callback Function)

-- Trigger when finished the refresh

-- Using like onBegin

top:

-- Set top of the refresher.

-- You can change its position finally by setting this option.

-- Default{ Type1 :'0px', Type2: depend on the height and top of the nav element }

var opts = {
  top: '50px'
}
theme: (Default: 'mui-blue-theme')

-- Set color or custom style of the refresher.

-- You can write your own style in css file by using the className like 'mui-somecolor-theme'

var opts = {
  theme: 'mui-red-theme'
}
index:

-- Set z-index of the refresher to change it in z-space.

-- Default { Type1: 10001, Type2: (the z-index of nav element) - 1}

var opts = {
  index: 99
}
maxTime: (Default: 6000ms)

-- Refresher will stop after the maxTime if you don't use mRefresh.resolve() to stop it.

-- You can change this maxTime to make it longer or shorter.

var opts = {
  maxTime: 2000
}
freeze: (Default: false)

-- The touch event of the refresher will not trigger if freeze is true.

-- You can use this option to prevent Type1 or Type2 and just allow Type3: button action

var opts = {
  freeze: true
}

Type1: Above surface

You can custom your own refresher like:

var opts = {
    maxTime: 3000,
    onBegin: function(){
      $.get('/whatevs.html', function(response){
        $('#someDom').append(response);
      });
    },
    onEnd: function(){
      alert('Finish the refresh');
    }
}

mRefresh(opts);

Type2: Below surface

Use Type2 by setting the option nav to the top of the elements:

// example
var opts = {
    nav: '#navMain',
    onBegin: function(){
      $.get('/whatevs.html', function(response){
        $('#someDom').append(response);
      });
    }
}

mRefresh(opts);

Then the refresher will below the surface of the navMain element.

Type3: Button action

If you had inited the refresher,you can bind the DOM event by using:

$('#buttonAction').on('tap', function(){
  mRefresh.refresh();
});

When you click the buttonAction element, the refresher will show.

If you want to get some callback when start or stop to refresh,by using onBegin or onEnd:

$('#buttonAction').on('tap', function(){
  var refreshOpts = {
    onBegin: function(){
      // Do something
      $.get('/whatevs.html', function(response){
        $('#someDom').append(response);
      });
    },
    onEnd: function(){
      alert('Finish!')
    }
  }
  mRefresh.refresh(refreshOpts);
});

If you want not to trigger Type1 or Type2, and just need Type3.

var opts = {
  freeze: true
}
mRefresh(opts);

$('#buttonAction').on('tap', function(){
  mRefresh.refresh();
});

Or

mRefresh();
mRefresh.unbindEvents();

$('#buttonAction').on('tap', function(){
  mRefresh.refresh();
});

Browser support

Android 3 +

iOS 5 +

Resource

Google Material Design

License

MIT © Gctang

主要指標

概覽
名稱與所有者lightningtgc/material-refresh
主編程語言JavaScript
編程語言CSS (語言數: 3)
平台
許可證
所有者活动
創建於2015-02-07 10:30:38
推送於2017-05-17 19:40:54
最后一次提交2015-09-09 00:08:03
發布數1
最新版本名稱v0.1.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數646
關注者數27
派生數108
提交數50
已啟用問題?
問題數17
打開的問題數17
拉請求數0
打開的拉請求數2
關閉的拉請求數3
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?