Fix positioning during scroll (TODO: maybe make lightbox position:fixed)
parent
d8570a63b7
commit
472aa4f3b1
17
slimbox2.js
17
slimbox2.js
|
@ -20,7 +20,7 @@ window.removeListener = (function() {
|
|||
addListener(window, 'load', function() {
|
||||
|
||||
// Global variables, accessible to Slimbox only
|
||||
var options, images, activeImage = -1, activeURL, prevImage, nextImage, compatibleOverlay, middle, centerWidth, centerHeight,
|
||||
var options, images, activeImage = -1, activeURL, prevImage, nextImage, noFixed, middle, centerWidth, centerHeight,
|
||||
ie6 = !window.XMLHttpRequest, hiddenElements = [], els = {}, css, keyActions,
|
||||
// Preload images
|
||||
preload = {}, preloadPrev = new Image(), preloadNext = new Image();
|
||||
|
@ -59,6 +59,9 @@ addListener(window, 'load', function() {
|
|||
f(i, a[i]);
|
||||
}
|
||||
}
|
||||
function curStyle(e) {
|
||||
return window.getComputedStyle ? getComputedStyle(e) : e.currentStyle;
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
|
@ -107,7 +110,8 @@ addListener(window, 'load', function() {
|
|||
startImage = 0;
|
||||
}
|
||||
|
||||
middle = document.documentElement.scrollTop + ((window.innerHeight || document.documentElement.offsetHeight) / 2);
|
||||
middle = (document.documentElement.scrollTop || document.body.scrollTop) +
|
||||
((window.innerHeight || document.documentElement.offsetHeight) / 2);
|
||||
centerWidth = options.initialWidth;
|
||||
centerHeight = options.initialHeight;
|
||||
apply(els.center.style, {
|
||||
|
@ -117,8 +121,9 @@ addListener(window, 'load', function() {
|
|||
marginLeft: (-centerWidth/2)+'px',
|
||||
display: ''
|
||||
});
|
||||
compatibleOverlay = ie6 || (els.overlay.style && (els.overlay.style.position != "fixed"));
|
||||
if (compatibleOverlay) els.overlay.style.position = "absolute";
|
||||
var cs = curStyle(els.overlay);
|
||||
noFixed = ie6 || cs && cs.position != "fixed";
|
||||
if (noFixed) els.overlay.style.position = "absolute";
|
||||
|
||||
els.overlay.style.display = '';
|
||||
setTimeout(function() {
|
||||
|
@ -153,10 +158,10 @@ addListener(window, 'load', function() {
|
|||
function position() {
|
||||
var l = document.documentElement.scrollLeft, w = document.documentElement.offsetWidth;
|
||||
els.center.style.left = els.bottomContainer.style.left = (l + (w / 2))+'px';
|
||||
if (compatibleOverlay) {
|
||||
if (noFixed) {
|
||||
apply(els.overlay.style, {
|
||||
left: l+'px',
|
||||
top: document.documentElement.scrollTop+'px',
|
||||
top: '0px',
|
||||
width: w+'px',
|
||||
height: document.documentElement.offsetHeight+'px'
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue