Skip to content

Instantly share code, notes, and snippets.

View imhuynq's full-sized avatar
👍
Luck Struck Here

Huy Nguyen imhuynq

👍
Luck Struck Here
View GitHub Profile
@tylerchilds
tylerchilds / createScrollManager.js
Created June 4, 2019 02:02
Use requestAnimationFrame to handle scrolling smoothly
const createScrollManager = function() {
let callbacks = [];
let scrollPosition = -1;
let animatedKilled = false;
const animate = () => {
requestAnimationFrame(onScroll);
}
function onScroll(){
@Godofbrowser
Godofbrowser / axios.refresh_token.1.js
Last active April 26, 2024 12:57 — forked from culttm/axios.refresh_token.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@SleepWalker
SleepWalker / swipe.js
Created September 30, 2015 04:59
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
@Warry
Warry / Article.md
Created December 11, 2012 00:11
How to make faster scroll effects?

How to make faster scroll effects?

  • Avoid too many reflows (the browser to recalculate everything)
  • Use advanced CSS3 for graphic card rendering
  • Precalculate sizes and positions

Beware of reflows

The reflow appens as many times as there are frames per seconds. It recalculate all positions that change in order to diplay them. Basically, when you scroll you execute a function where you move things between two reflows. But there are functions that triggers reflows such as jQuery offset, scroll... So there are two things to take care about when you dynamically change objects in javascript to avoid too many reflows: