minor fixes

This commit is contained in:
Ilya Kantor 2019-11-30 09:31:19 +03:00
parent 6a52ee2cf5
commit d334cf8787
2 changed files with 2 additions and 32 deletions

View file

@ -279,7 +279,7 @@ What if we'd like to fix some arguments, but not the context `this`? For example
The native `bind` does not allow that. We can't just omit the context and jump to arguments. The native `bind` does not allow that. We can't just omit the context and jump to arguments.
Fortunately, a helper function `partial` for binding only arguments can be easily implemented. Fortunately, a function `partial` for binding only arguments can be easily implemented.
Like this: Like this:

View file

@ -169,39 +169,9 @@
* It's enough that the top or bottom edge of the element are visible * It's enough that the top or bottom edge of the element are visible
*/ */
function isVisible(elem) { function isVisible(elem) {
// todo: your code
let coords = elem.getBoundingClientRect();
let windowHeight = document.documentElement.clientHeight;
// top elem edge is visible OR bottom elem edge is visible
let topVisible = coords.top > 0 && coords.top < windowHeight;
let bottomVisible = coords.bottom < windowHeight && coords.bottom > 0;
return topVisible || bottomVisible;
} }
/**
A variant of the test that considers the element visible if it's no more than
one page after/behind the current screen.
function isVisible(elem) {
let coords = elem.getBoundingClientRect();
let windowHeight = document.documentElement.clientHeight;
let extendedTop = -windowHeight;
let extendedBottom = 2 * windowHeight;
// top visible || bottom visible
let topVisible = coords.top > extendedTop && coords.top < extendedBottom;
let bottomVisible = coords.bottom < extendedBottom && coords.bottom > extendedTop;
return topVisible || bottomVisible;
}
*/
function showVisible() { function showVisible() {
for (let img of document.querySelectorAll('img')) { for (let img of document.querySelectorAll('img')) {
let realSrc = img.dataset.src; let realSrc = img.dataset.src;