Search code examples
sliderjssor

JSSOR Slider Min-Height change needed


"jssor slider will always keep aspect ratio while scale. so min-height is not reasonable"

hi all, i need a min-height function for the image in order to keep my page layout consistent.

Does anyone know how to modify the js code?

A flexible dynamic width is good but at some point i need a min-height to anchor the image to a consistent page layout.

thanks


Solution

  • //responsive code begin
    //you can remove responsive code if you don't want the slider scales while window resizes
    function ScaleSlider() {
        var parentWidth = jssor_slider1.$Elmt.parentNode.clientWidth;
        if (parentWidth) {
            //for example minHeight is 300;
            var minHeight = 300;
    
            var newWidth = parentWidth;
            var newHeight = jssor_slider1.$OriginalHeight() / jssor_slider1.$OriginalWidth() * newWidth;
    
            if (newHeight < minHeight)
                jssor_slider1.$ScaleHeight(minHeight);
            else
                jssor_slider1.$ScaleWidth(parentWidth);
        }
        else
            window.setTimeout(ScaleSlider, 30);
    }
    ScaleSlider();
    
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
    //responsive code end