Skip to content

Commit

Permalink
Improve the support of tactile device
Browse files Browse the repository at this point in the history
-> The lazyload is not support by iOS device (see vvo#59)
-> Add a listener on the touchmove event that is fired before the scroll event.
  • Loading branch information
abarre committed Jun 6, 2014
1 parent 2b62c36 commit 37333b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
11 changes: 8 additions & 3 deletions lazyload.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ if (!window['lzld']) {

// throttled functions, so that we do not call them too much
saveViewportT = throttle(viewport, 20),
showImagesT = throttle(showImages, 20);
showImagesT = throttle(showImages, 20),
isiOSDevice = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );

// Override image element .getAttribute globally so that we give the real src
// does not works for ie < 8: http://perfectionkills.com/whats-wrong-with-extending-the-dom/
Expand Down Expand Up @@ -175,11 +176,13 @@ if (!window['lzld']) {
// img = dom element
// index = imgs array index
function showIfVisible(img, index) {
// Note that iOS devices freeze DOM manipulation during scroll, queuing them to apply when the scroll finishes.
// So it's better to disable the lazyloading on iOS device.
// We have to check that the current node is in the DOM
// It could be a detached() dom node
// http://bugs.jquery.com/ticket/4996
if (contains(document.documentElement, img)
&& img.getBoundingClientRect().top < winH + offset) {
if (isiOSDevice || (contains(document.documentElement, img)
&& img.getBoundingClientRect().top < winH + offset)) {
// To avoid onload loop calls
// removeAttribute on IE is not enough to prevent the event to fire
img.onload = null;
Expand Down Expand Up @@ -240,13 +243,15 @@ if (!window['lzld']) {
unsubscribed = true;
removeEvent(window, 'resize', saveViewportT);
removeEvent(window, 'scroll', showImagesT);
removeEvent(window, 'touchmove', showImagesT);
removeEvent(window, 'load', onLoad);
}

function subscribe() {
unsubscribed = false;
addEvent(window, 'resize', saveViewportT);
addEvent(window, 'scroll', showImagesT);
addEvent(window, 'touchmove', showImagesT);
}

function overrideGetattribute() {
Expand Down
11 changes: 5 additions & 6 deletions lazyload.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 37333b2

Please sign in to comment.