Created
July 1, 2014 22:14
-
-
Save navio/2d1f0ca1372f7652444b to your computer and use it in GitHub Desktop.
Lazy Load Tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var images = Array.prototype.slice.call( document.querySelectorAll('img') ); | |
// Disable Images - if not from BackEnd | |
images.forEach( function(image){ | |
var source = image.getAttribute("src"); | |
image.setAttribute("src", ""); | |
image.setAttribute("data-src", source); | |
}); | |
// Set Location for future Process | |
images.forEach(function(element){ | |
var xPosition = 0; | |
var yPosition = 0; | |
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft); | |
yPosition += (element.offsetTop - element.scrollTop + element.clientTop); | |
element.x = xPosition; | |
element.y = yPosition; | |
return 1; | |
}); | |
// Make visible images visible. | |
images.forEach(function(element){ | |
}); | |
// Visible Area | |
function windowSize(){ | |
var da = window.innerHeight + | |
} | |
// Element Area | |
function elementSize(element){ | |
var element = element.clientHeight; | |
} | |
// Check if visible. $jquery | |
$.fn.if_visible = function(){ | |
var win = $(window); | |
var viewport = { | |
top : win.scrollTop(), | |
left : win.scrollLeft() | |
}; | |
viewport.right = viewport.left + win.width(); | |
viewport.bottom = viewport.top + win.height(); | |
var bounds = this.offset(); | |
bounds.right = bounds.left + this.outerWidth(); | |
bounds.bottom = bounds.top + this.outerHeight(); | |
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)); | |
}; | |
// Function get position | |
function getPosition(element) { | |
var xPosition = 0; | |
var yPosition = 0; | |
while(element) { | |
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft); | |
yPosition += (element.offsetTop - element.scrollTop + element.clientTop); | |
element = element.offsetParent; | |
} | |
return { x: xPosition, y: yPosition }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First Attempts.