Simplify animation js

master
vitalif 2015-05-01 16:39:47 +00:00
parent e04c0b25b6
commit 460bbdd071
3 changed files with 7 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* SLIMBOX version 2015-04-30 */ /* SLIMBOX version 2015-05-01 */
#lbOverlay { #lbOverlay {
position: fixed; position: fixed;

View File

@ -1,4 +1,4 @@
/* SLIMBOX version 2015-04-30 */ /* SLIMBOX version 2015-05-01 */
#lbOverlay { #lbOverlay {
position: fixed; position: fixed;

View File

@ -3,7 +3,7 @@
Based on and mostly compatible with Slimbox2 <http://www.digitalia.be/software/slimbox2> Based on and mostly compatible with Slimbox2 <http://www.digitalia.be/software/slimbox2>
(c) 2012+ Vitaliy Filippov <http://yourcmc.ru/wiki> (c) 2012+ Vitaliy Filippov <http://yourcmc.ru/wiki>
MIT-style license. MIT-style license.
Version 2015-04-30 Version 2015-05-01
*/ */
window.addListener = (function() { window.addListener = (function() {
@ -224,6 +224,7 @@ addListener(window, 'load', function() {
nextImage = ((activeImage + 1) % images.length) || (options.loop ? 0 : -1); nextImage = ((activeImage + 1) % images.length) || (options.loop ? 0 : -1);
els.center.className = "lbLoading"; els.center.className = "lbLoading";
els.image.className = '';
preload = new Image(); preload = new Image();
preload.onload = animateBox; preload.onload = animateBox;
@ -236,7 +237,6 @@ addListener(window, 'load', function() {
function animateBox() { function animateBox() {
els.center.className = ""; els.center.className = "";
els.image.style.backgroundImage = "url(" + activeURL + ")"; els.image.style.backgroundImage = "url(" + activeURL + ")";
els.image.style.display = '';
els.image.style.marginLeft = (-preload.width/2)+'px'; els.image.style.marginLeft = (-preload.width/2)+'px';
els.image.style.marginTop = (-preload.height/2)+'px'; els.image.style.marginTop = (-preload.height/2)+'px';
els.image.style.width = preload.width+'px'; els.image.style.width = preload.width+'px';
@ -251,25 +251,20 @@ addListener(window, 'load', function() {
centerWidth = preload.width; centerWidth = preload.width;
centerHeight = preload.height; centerHeight = preload.height;
if (els.window.offsetHeight != centerHeight) { if (els.window.clientHeight != centerHeight) {
var top = Math.max(0, middle - (centerHeight / 2)); var top = Math.max(0, middle - (centerHeight / 2));
els.window.style.paddingTop = els.window.style.paddingBottom = (centerHeight/2)+'px'; els.window.style.paddingTop = els.window.style.paddingBottom = (centerHeight/2)+'px';
els.center.style.top = top+'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.window.style.paddingLeft = els.window.style.paddingRight = (centerWidth/2)+'px';
els.center.style.marginLeft = (-centerWidth/2)+'px'; els.center.style.marginLeft = (-centerWidth/2)+'px';
} }
els.image.className = ''; els.image.className = 'lbvisible';
setTimeout(showImg, 15);
if (prevImage >= 0) els.prevLink.style.display = ''; if (prevImage >= 0) els.prevLink.style.display = '';
if (nextImage >= 0) els.nextLink.style.display = ''; if (nextImage >= 0) els.nextLink.style.display = '';
} }
function showImg() {
els.image.className = 'lbvisible';
}
function stop() { function stop() {
preload.onload = null; preload.onload = null;
preload.src = preloadPrev.src = preloadNext.src = activeURL; preload.src = preloadPrev.src = preloadNext.src = activeURL;