Search code examples
javascriptjssor

JSSOR: Slider Can't Scale Properly on Load


I am trying to figure out how to scale JSSOR container height on page load.

When the slider loads on high width page, the slider width and height scale smoothly when it's resized. But when the page loads on mobile, the container height won't scale like it does when the slider loads on high width page.

Here is the problem: http://screencast.com/t/W6fldyjtuCAp

It works properly when resized from high width page load: http://screencast.com/t/1lErSBxu

But when I see the demo on JSSOR site, the scale works smoothly on mobile page load. Here are my JSSOR code:

jssor_slider1_starter = function (containerId) {

        var options = {

            $AutoPlay: true,                                    //[Optional] Whether to auto play, to enable slideshow, this option must be set to true, default value is false

            $AutoPlaySteps: 1,                                  //[Optional] Steps to go for each navigation request (this options applys only when slideshow disabled), the default value is 1

            $AutoPlayInterval: 4000,                            //[Optional] Interval (in milliseconds) to go for next slide since the previous stopped if the slider is auto playing, default value is 3000

            $PauseOnHover: 1,                               //[Optional] Whether to pause when mouse over if a slider is auto playing, 0 no pause, 1 pause for desktop, 2 pause for touch device, 3 pause for desktop and touch device, 4 freeze for desktop, 8 freeze for touch device, 12 freeze for desktop and touch device, default value is 1

            $Loop: 0,                                       //[Optional] Enable loop(circular) of carousel or not, 0: stop, 1: loop, 2 rewind, default value is 1

            $ArrowKeyNavigation: true,                          //[Optional] Allows keyboard (arrow key) navigation or not, default value is false

            $SlideDuration: 500,                                //[Optional] Specifies default duration (swipe) for slide in milliseconds, default value is 500

            $MinDragOffsetToSlide: 20,                          //[Optional] Minimum drag offset to trigger slide , default value is 20

            $SlideSpacing:0,                                    //[Optional] Space between each slide in pixels, default value is 0

            $Cols: 1,                                  //[Optional] Number of pieces to display (the slideshow would be disabled if the value is set to greater than 1), the default value is 1

            $Align: 0,                                //[Optional] The offset position to park slide (this options applys only when slideshow disabled), default value is 0.

            $UISearchMode: 1,                                   //[Optional] The way (0 parellel, 1 recursive, default value is 1) to search UI components (slides container, loading screen, navigator container, arrow navigator container, thumbnail navigator container etc).

            $PlayOrientation: 1,                                //[Optional] Orientation to play slide (for auto play, navigation), 1 horizental, 2 vertical, 5 horizental reverse, 6 vertical reverse, default value is 1

            $DragOrientation: 3,                                //[Optional] Orientation to drag slide, 0 no drag, 1 horizental, 2 vertical, 3 either, default value is 1 (Note that the $DragOrientation should be the same as $PlayOrientation when $Cols is greater than 1, or parking position is not 0)

            $FillMode: 1,



            $ThumbnailNavigatorOptions: {

                $Class: $JssorThumbnailNavigator$,              //[Required] Class to create thumbnail navigator instance

                $ChanceToShow: 2,                               //[Required] 0 Never, 1 Mouse Over, 2 Always

                $Loop: 2,                                       //[Optional] Enable loop(circular) of carousel or not, 0: stop, 1: loop, 2 rewind, default value is 1

                $Rows: 1,                                      //[Optional] Specify lanes to arrange thumbnails, default value is 1

                $SpacingX: 4,                                   //[Optional] Horizontal space between each thumbnail in pixel, default value is 0

                $SpacingY:0,                                   //[Optional] Vertical space between each thumbnail in pixel, default value is 0

                $Cols: 4,                              //[Optional] Number of pieces to display, default value is 1

                $Align: 0,                            //[Optional] The offset position to park thumbnail

                $Orientation: 2,                                //[Optional] Orientation to arrange thumbnails, 1 horizental, 2 vertical, default value is 1

                $NoDrag: false                             //[Optional] Disable drag or not, default value is false

            }



        };



        var jssor_slider1 = new $JssorSlider$(containerId, 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) {
                var sliderWidth = parentWidth;

                //keep the slider width no more than 810
                sliderWidth = Math.min(sliderWidth, 1000);

                jssor_slider1.$ScaleWidth(sliderWidth);
            }
            else
                $Jssor$.$Delay(ScaleSlider, 30);
        }

        ScaleSlider();
        // $Jssor$.$AddEvent(window, "load", ScaleSlider);
        $Jssor$.$AddEvent(window, "load", $Jssor$.$WindowResizeFilter(window, ScaleSlider));

        $Jssor$.$AddEvent(window, "resize", $Jssor$.$WindowResizeFilter(window, ScaleSlider));
        $Jssor$.$AddEvent(window, "orientationchange", ScaleSlider);
        //responsive code end
}

jssor_slider1_starter('slider1_container');

What am I missing here? I tried to match the code with JSSOR demo options but it didn't work either.

Thanks is advance!


Solution

  • I've managed to solve this problem. Initially I use % width for slider container, slide image and thumbnail skin CSS. Then I changed it to px width and it works perfectly now.