Last active
August 29, 2015 14:04
-
-
Save dgtlmonk/d983b358ef39fd448979 to your computer and use it in GitHub Desktop.
This file contains 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
window.addEventListener('scroll', function(){ | |
if (vOverlay) { | |
vOverlay.style.top = window.pageYOffset + "px"; | |
vOverlay.style.left = window.pageXOffset + "px"; | |
} | |
}, false); | |
window.addEventListener('resize', function(){ | |
if (vOverlay) { | |
vOverlay.style.top = window.pageYOffset + "px"; | |
vOverlay.style.left = window.pageXOffset + "px"; | |
vOverlay.style.width = window.innerWidth + "px"; | |
vOverlay.style.height = window.innerHeight + "px"; | |
} | |
}, false); | |
/* Usage: | |
LargeImg.addEventListener('load', function() { | |
// resize if taller | |
if (this.height > window.innerHeight) { | |
this.ratio = window.innerHeight / this.height; | |
this.height = this.height * this.ratio; | |
this.width - this.width * this.ratio; | |
} | |
// if wider | |
if (this.width > window.innerWidth) { | |
this.ratio = window.innerWidth / this.width; | |
this.height = this.height * this.ratio; | |
this.width - this.width * this.ratio; | |
} | |
centerImage(this); | |
vOverlay.appendChild(LargeImg); | |
}); // image has loaded | |
*/ | |
function centerImage( img ) { | |
var diffX = (window.innerWidth - img.width) / 2; | |
var diffY = (window.innerHeight - img.height) / 2; | |
img.style.top = diffY + "px"; | |
img.style.left = diffX + "px"; | |
return img; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment