A native-like JavaScript pull to refresh implementation for the web.

Overview

Pull to Refresh for the Web 1.1

Web Pull to Refresh

This is a pull to refresh implementation for the web. It focuses on buttery UX performance and responsiveness to feel as close to a native implementation as possible.

Try a Demo | Read the Blog Post

Usage

There are two core elements needed, the content element and the pull to refresh UX element. The demo uses this setup, but you can modify this however you'd like.

<div id="ptr">
  <!-- Pull down arrow indicator -->
  <span class="genericon genericon-next"></span>

  <!-- CSS-based loading indicator -->
  <div class="loading">
    <span id="l1"></span>
    <span id="l2"></span>
    <span id="l3"></span>
  </div>
</div>

<div id="content">
  <!-- Content that should be draggable for refreshing goes in here -->
</div>

This will work just fine with your own loading indicators or pull down arrow, just make sure they're wrapped in the element you're using to hold the pull to refresh UX. Don't forget to include the CSS if you want to use a similar visual setup as the demo.

In order for this to function, you'll need to load both Hammer.js and the wptr.js script, and then initialize the WebPullToRefresh module. Add this just before the closing body tag:

<script src="lib/hammer.2.0.4.js"></script>
<script src="lib/wptr.1.0.js"></script>

<script>
  window.onload = function() {
    WebPullToRefresh.init( {
      loadingFunction: exampleLoadingFunction
    } );
  };
</script>

You will also need to provide a loading function at initization time. This function should perform the async loading pieces you need to load new items, and return a promise.

var exampleLoadingFunction = function() {
  return new Promise( function( resolve, reject ) {
    // Run some async loading code here

    if ( /* if the loading worked */ ) {
      resolve();
    } else {
      reject();
    }
  } );
};

Optional Parameters

There are a few optional parameters you can pass on initialization:

{
	// ID of the element holding dragable content area
	contentEl: 'content', 

	// ID of the element holding pull to refresh loading area
	ptrEl: 'ptr', 

	// Number of pixels of dragging down until refresh will fire
	distanceToRefresh: 70, 

  // The dragging resistance level, the higher the more you'll need to drag down.
  resistance: 2.5
}

Try a Demo | Read the Blog Post

Comments
  • not working with the new version of hammer js

    not working with the new version of hammer js

    Hi,

    I love the demo and it is works great! But when I am trying to integrate the code to my site, I found it is not working with the new version of the hammer js. (v2.0.4)

    is it possible to work with the new version?

    Plz advise.

    thx.

    opened by jackyon 6
  • Demo doesn't work on Windows Phone

    Demo doesn't work on Windows Phone

    Works a treat in Chrome on my desktop, but in testing on Windows Phone, this doesn't work, any ideas why this might be? Happy to work with you to get this working.

    opened by HammyHavoc 2
  • Where do i add in the optional parameters??

    Where do i add in the optional parameters??

    I am not sure where do i change these, if i change the contentEI inside the wptr.1.1.js then the "animation" part stopped working.

    {
        // ID of the element holding dragable content area
        contentEl: 'content', 
    
        // ID of the element holding pull to refresh loading area
        ptrEl: 'ptr', 
    
        // Number of pixels of dragging down until refresh will fire
        distanceToRefresh: 70, 
    
      // The dragging resistance level, the higher the more you'll need to drag down.
      resistance: 2.5
    }
    
    opened by clarklight 0
  • Doesnt work on webkit (touch devices) and android web view

    Doesnt work on webkit (touch devices) and android web view

    Tried with Google Chrome Version 59.0.3071.86 (Official Build) (64-bit) Tried with Android Web View version 58 It stuck on pull down. However it happens only when selects a touch device http://pix.toile-libre.org/upload/original/1498626667.png

    opened by razcakappa 2
  • does not work if merged with bootstrap

    does not work if merged with bootstrap

    Hello Andy, I pulled your repo and installed it on my tiny web site index page : https://goo.gl/9fEs3e

    It doesn't give any error but doesnt work either.

    you can see my index.htm that has your library included for the above live link.

    opened by sanfx 1
Releases(1.1.0)
A quick and powerful plugin for your pull-to-refresh needs in your webapp.

PulltoRefresh.js • Demos A small, but powerful Javascript library crafted to power your webapp's pull to refresh feature. No markup needed, highly cus

Box Factura 3.9k Jan 6, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Make your first Pull Request on Hacktoberfest 2022. Don't forget to spread love and if you like give us a star

Hacktoberfest2022 Make your first Pull Request on Hacktoberfest 2022. Don't forget to spread love and if you like give us a star Quality of Pull Reque

Google Developer Students Club - Galgotias University 12 Oct 30, 2022
Refresh - Simple browser reload on file change middleware for your Deno web applications.

refresh Simple browser reload on file change middleware for your Deno web applications. Usage To use refresh middleware, just add a few extra lines to

Craig Morten 13 Dec 19, 2022
Clinton Mbonu 20 Jun 30, 2022
This project is built with JavaScript, Webpack, HTML & CSS, Leaderboard api. When user clicks on Refresh button it hits the api and responds with the data, The user can also post data to the api

leaderboad Description the project. this project is about the leaderboad i did during Microverse to build a website for adding Data to the API and fet

Emmanuel Moombe 4 May 30, 2022
A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebWorker like neither of those.

Amuchina A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebW

Fabio Spampinato 9 Sep 17, 2022
This project is about Leaderboard list app, that allows users to add score to the list and refresh the list.

Leaderboard This project is about Leaderboard list app, that allows users to add score to the list and refresh the list. Built With JavaScript HTML CS

Mihreteab Misganaw 3 Dec 19, 2021
Google Cloud Platform Refresh Token

Google Cloud Platform Refresh Token gcp-refresh-token is a cli util from plasmo to retrieve a refresh token as specified in Google's OAuth 2.0 Refresh

Plasmo 3 Jun 7, 2022
A leaderboard created using Leaderboard API service, Webpack, and Gitflow. The user can add a new score and refresh to see his ranking in the leaderboard.

Leaderboard A leaderboard created using Leaderboard API service, webpack, and gitflow. The user can add a new score and refresh to see his ranking in

ABDUL ALI 13 Dec 26, 2022
CLI tool to update caniuse-lite to refresh target browsers from Browserslist config

Update Browserslist DB CLI tool to update caniuse-lite with browsers DB from Browserslist config. Some queries like last 2 version or >1% depends on a

Browserslist 31 Dec 30, 2022
JOSE ZEPEDA 10 Nov 18, 2022
leaderBoard is a project used to add a score, view score list, and refresh score list. It is built using JS, HTML, BootStrap, and API.

LeaderBoard ?? Table of Contents ?? About the Project ?? Built With Tech Stack Key Features ?? Live Demo ?? Getting Started Setup Prerequisites Instal

Zewdie Habtie 4 Mar 20, 2023
Next-level academia! Repository for the Native Overleaf project, attempting to integrate Overleaf with native OS features for macOS, Linux and Windows.

Native Overleaf Overleaf is a fantastic webtool for writing and cooperating on LaTeX documents. However, would it not be even better if it were to beh

Floris-Jan Willemsen 40 Dec 18, 2022
Like JSX, but native and fast

esx High throughput React Server Side Rendering For a simplified example of esx in action, check out esx-demo. esx is designed to be a high speed SSR

ESX 645 Jan 2, 2023
Multiple level dropdown works with Bootstrap 5, just like native support.

Bootstrap 5 Multiple Level Dropdown. For Bootstrap 4, please visit Bootstrap 4 Multiple Level Dropdown Using official HTML without adding extra CSS st

Dallas Lu 17 Dec 13, 2022