Upgrade to Pro — share decks privately, control downloads, hide ads and more …

No me robes el Scroll!

No me robes el Scroll!

Viste cuando scrolleas y anda todo re lento? Bueno, muchas veces por ser cool y hacer un montón de cosas en el scroll penalizamos al usuario y su experiencia sin darnos cuenta. Por eso, les quiero compartir una técnica para evitar esto y tener UIs mucho más performantes.

Guille Paz

July 14, 2016
Tweet

More Decks by Guille Paz

Other Decks in Technology

Transcript

  1. • Headers Fixed • Parallax Scrolling • History API •

    Custom Scrolls • Position Fixed • Hover on Scroll (Chrome NO!) • Juan Vanni <3
  2. “It’s a very, very, bad idea to attach handlers to

    the window scroll event.” by John Resig
  3. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false; } node.addEventListener('scroll', captureScroll, false); }
  4. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false; } node.addEventListener('scroll', captureScroll, false); }
  5. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false;
  6. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve);
  7. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false; }
  8. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false; } node.addEventListener('scroll', captureScroll, false); } function foo(eve) { console.log(eve); console.log(this.scrollTop); } var nodeBox = $$.querySelector('#box'); decouple(nodeBox, foo);
  9. function decouple(node, fn) { var eve, tracking = false; function

    captureScroll(e) { eve = e; track(); } function track() { if (!tracking) { requestAnimationFrame(update); tracking = true; } } function update() { fn.call(node, eve); tracking = false; } node.addEventListener('scroll', captureScroll, false); }