From 460bbdd071737a04c48dff4086ac608ce1047818 Mon Sep 17 00:00:00 2001 From: vitalif Date: Fri, 1 May 2015 16:39:47 +0000 Subject: [PATCH] Simplify animation js --- slimbox2-rtl.css | 2 +- slimbox2.css | 2 +- slimbox2.js | 15 +++++---------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/slimbox2-rtl.css b/slimbox2-rtl.css index 275c54a..98dfdbb 100644 --- a/slimbox2-rtl.css +++ b/slimbox2-rtl.css @@ -1,4 +1,4 @@ -/* SLIMBOX version 2015-04-30 */ +/* SLIMBOX version 2015-05-01 */ #lbOverlay { position: fixed; diff --git a/slimbox2.css b/slimbox2.css index 7c9d852..ddabe82 100644 --- a/slimbox2.css +++ b/slimbox2.css @@ -1,4 +1,4 @@ -/* SLIMBOX version 2015-04-30 */ +/* SLIMBOX version 2015-05-01 */ #lbOverlay { position: fixed; diff --git a/slimbox2.js b/slimbox2.js index 4883420..85a57a6 100644 --- a/slimbox2.js +++ b/slimbox2.js @@ -3,7 +3,7 @@ Based on and mostly compatible with Slimbox2 (c) 2012+ Vitaliy Filippov MIT-style license. - Version 2015-04-30 + Version 2015-05-01 */ window.addListener = (function() { @@ -224,6 +224,7 @@ addListener(window, 'load', function() { nextImage = ((activeImage + 1) % images.length) || (options.loop ? 0 : -1); els.center.className = "lbLoading"; + els.image.className = ''; preload = new Image(); preload.onload = animateBox; @@ -236,7 +237,6 @@ addListener(window, 'load', function() { function animateBox() { els.center.className = ""; els.image.style.backgroundImage = "url(" + activeURL + ")"; - els.image.style.display = ''; els.image.style.marginLeft = (-preload.width/2)+'px'; els.image.style.marginTop = (-preload.height/2)+'px'; els.image.style.width = preload.width+'px'; @@ -251,25 +251,20 @@ addListener(window, 'load', function() { centerWidth = preload.width; centerHeight = preload.height; - if (els.window.offsetHeight != centerHeight) { + if (els.window.clientHeight != centerHeight) { var top = Math.max(0, middle - (centerHeight / 2)); els.window.style.paddingTop = els.window.style.paddingBottom = (centerHeight/2)+'px'; els.center.style.top = top+'px'; } - if (els.window.offsetWidth != centerWidth) { + if (els.window.clientWidth != centerWidth) { els.window.style.paddingLeft = els.window.style.paddingRight = (centerWidth/2)+'px'; els.center.style.marginLeft = (-centerWidth/2)+'px'; } - els.image.className = ''; - setTimeout(showImg, 15); + els.image.className = 'lbvisible'; if (prevImage >= 0) els.prevLink.style.display = ''; if (nextImage >= 0) els.nextLink.style.display = ''; } - function showImg() { - els.image.className = 'lbvisible'; - } - function stop() { preload.onload = null; preload.src = preloadPrev.src = preloadNext.src = activeURL;