resize script for galleria

2019-02-19 09:09发布

I'm wanting to resize the entire galleria div and resize all the images dynamically generated using the galleria script.

so far I have

    $(window).resize(function() {
    var h = $(window).height();
    var galleriaHeight = h-54;
    var w = $(".content").width();
    var galleriaWidth = w-18;

    $("#galleria").height(galleriaHeight);
    $("#galleria").width(w);


    $(".galleria-stage").height(galleriaHeight);
    $(".galleria-stage").width(galleriaWidth);

    $(".galleria-images .galleria-image img").css({"max-height":"auto"});
    $(".galleria-images .galleria-image img").css({"max-width":galleriaWidth-36});

    $(".galleria-stage").height(galleriaHeight);
    $(".galleria-stage").width(galleriaWidth);

    $(".galleria-container").width(w);
    $(".galleria-container").height(galleriaHeight);

    $(".caption").width(w);
    $(".counter-nav").width(w);

    var sidebarHeight =h-54;
    var contentHeight =h-36;

    $(".sidebar1").height(sidebarHeight);
    $(".content").height(contentHeight);




});

But everything is scaling unevenly and very messed up. Having looked at the fullscreen code, I have also added

this.bind(Galleria.RESCALE, function() {
 POS = this.getStageHeight() - tab.height() - 2;
 thumbs.css('top', OPEN ? POS - list.outerHeight() + 2 : POS);
 var img = this.getActiveImage();
 if (img) 
     {
     fixCaption(img);
     }
});

but that's not working either...

I suppose I want to reload the page after i resize but on the fly... or resize all elements relative to each other, or use the Galleria resize script ...

Any ideas?

1条回答
萌系小妹纸
2楼-- · 2019-02-19 09:35

I know this is old, but I don't see an answer anywhere. Hopefully it can help the next guy.

This will dynamically resize Galleria when the browser window is resized.

I ran into similar issues. I ended up binding the following function to the window resize event. I used the logic for the resize event from this post

First, set up the resize function:

          function ResizeGallery() {

                gWidth = $(window).width();
                gHeight = $(window).height();
                gWidth = gWidth - ((gWidth > 200) ? 100 : 0);
                gHeight = gHeight - ((gHeight > 100) ? 50 : 0);
                $("#gallerycontainer").width(gWidth);
                $("#gallery").width(gWidth);
                $("#gallery").height(gHeight);
   Galleria.loadTheme('js/galleria/themes/classic/galleria.classic.js', { show: curIdx });
        }

Then bind it to the window resize event:

   var TO = false;
    $(window).resize(function () {
        if (TO !== false)
            clearTimeout(TO);
        TO = setTimeout(ResizeGallery, 200); //200 is time in miliseconds
    });

This will essentially re-initialize by reloading the default theme. In this example, I am using the second parameter to specify which image to show- otherwise it will display the first image. Be aware that this may cause another instance of Galleria. I believe this to be a bug, and posted on their forums. You can remove the older instances as follows:

 var gcount = Galleria.get().length;

       if (gcount > 1) {
           Galleria.get().splice(0, gcount - 1);
       }

Run it after the loadTheme method. Use settimeout to delay it, because loadTheme takes some time to complete. I use 200ms. Ugly, but I need some of the features in Galleria. Hope this helps.

查看更多
登录 后发表回答