Jssor slider 100% width

后端 未结 5 1659
北荒
北荒 2020-12-03 01:17

I try to get a jssor slider working with 100% width (the container has a width of 70%). The problem is, that jssor only works with pixels, so if I use a slide_container with

5条回答
  •  [愿得一人]
    2020-12-03 02:11

    size of 'slide_container' should be always specified with fixed pixels. the original size is fixed then, but you can scale the slider to any size.

    use following code to scale the slider to width of document.body.

    var jssor_slider1 = new $JssorSlider$("slider1_container", options);
    
    //responsive code begin
    //you can remove responsive code if you don't want the slider scales while window resizes
    function ScaleSlider() {
        var bodyWidth = document.body.clientWidth;
        if (bodyWidth)
            jssor_slider1.$ScaleWidth(Math.min(bodyWidth, 1920));
        else
            window.setTimeout(ScaleSlider, 30);
    }
    ScaleSlider();
    
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
    //responsive code end
    

    also, you can scale the slider to width of parent element,

    var jssor_slider1 = new $JssorSlider$("slider1_container", options);
    
    //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)
            jssor_slider1.$ScaleWidth(Math.min(parentWidth, 1920));
        else
            window.setTimeout(ScaleSlider, 30);
    }
    ScaleSlider();
    
    $(window).bind("load", ScaleSlider);
    $(window).bind("resize", ScaleSlider);
    $(window).bind("orientationchange", ScaleSlider);
    //responsive code end
    

提交回复
热议问题