Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The option is added to load first frames only if it is shown in viewport #468

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/js/fotorama.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,34 @@ jQuery.Fotorama = function ($fotorama, opts) {
}
}

/**
* Defines whether fotorama in visible viewport.
* @param el - DOM element or jQuery object.
* @returns {boolean}
*/
function isInViewport() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use here clear functions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify your answer?

Copy link

@ghost ghost May 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all objects, variables used in your function must be in parameters. it rather useful because not affected on global scope and i think write more transparent code

var rect = $fotorama.get(0).getBoundingClientRect();
return (!!rect
&& rect.bottom >= 0
&& rect.right >= 0
&& rect.top <= document.documentElement.clientHeight
&& rect.left <= document.documentElement.clientWidth
);
}

if (opts.lazyLoad) {
addEvent(window, 'scroll', function () {
if (isInViewport()) {
reset();
}
});
}

function loadImg (indexes, type, specialMeasures, method, position, again) {
// Load only images visible in viewport.
if (that.options.lazyload && !isInViewport()) {
return false;
}
eachIndex(indexes, type, function (i, index, dataFrame, $frame, key, frameData) {

if (!$frame) return;
Expand Down