Skip to content

Instantly share code, notes, and snippets.

@navio
Created July 1, 2014 22:14
Show Gist options
  • Select an option

  • Save navio/2d1f0ca1372f7652444b to your computer and use it in GitHub Desktop.

Select an option

Save navio/2d1f0ca1372f7652444b to your computer and use it in GitHub Desktop.
Lazy Load Tests.
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 };
}
@navio

navio commented Jul 1, 2014

Copy link
Copy Markdown
Author

First Attempts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment