DEV Community

Pull to refresh animation with Vanilla JavaScript

vijitail on May 12, 2019

Pull-to-refresh is a very popular swipe gesture on smartphones that allow users to load new content on top of listed data. Its used in all popula...
Collapse
 
yegorsteshenko profile image
Yegor

This statement if (document.body.scrollTop === 0) constantly returns true and triggers reload animation every time you scroll up more than 100px, even if you at the very bottom of the page. Isn't is better to trigger animations only if you scroll up at the very top of the page? Like do this instead: if (window.scrollY === 0)

Collapse
 
bharathnallamothu profile image
bhaRATh

will it give me events like pull started , pull finessed? so that i can map it with server

Collapse
 
vijitail profile image
vijitail

Yes.. but currently these are not included in this post, you can add it easily using callbacks

Collapse
 
isalevine profile image
Isa Levine

this is so cool, thank you for sharing!!

Collapse
 
vijitail profile image
vijitail

I'm glad you found it helpful

Collapse
 
limbara profile image
Nico Limbara

let changeY = pStart.y < pCurrent.y? Math.abs(pStart.y - pCurrent.y) : 0; or it might trigger loading

Collapse
 
vijitail profile image
vijitail • Edited

Thanks man for pointing that out. Yes, otherwise it would trigger loading on swipe up as well. Great observations.

Collapse
 
okokokkkkkkjj profile image
.

what font do you use? I love the comparison operators look. :O

Collapse
 
vijitail profile image
vijitail • Edited

I created those images using carbon

But I guess the font is Fira Code

Collapse
 
flrnd profile image
Florian Rand
Collapse
 
chuksjoe profile image
Chukwunonso Orjiakor

Great post brother. Thanks for sharing 👍👍

Collapse
 
evankapantais profile image
Evan Kapantais

Is it really ok to self-close divs like that?

Collapse
 
vijitail profile image
vijitail

Yup